Mein Code:cellForRowAt nicht aber numberOfSection und numberOfRowsInSection genannt wird, wird aufgerufen wird
//Adding Destination VC as subview in my current view's view container
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "DestinationViewControllerID")
containerView.addSubview(viewController.view)
viewController.didMove(toParentViewController: self)
//Now implementing Table view in the destination vc
class DestinationViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var tableView = UITableView()
var tableData = ["Beach", "Clubs", "Chill", "Dance"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let screenBounds = UIScreen.main.bounds
let rect = CGRect(x: 0, y: 0, width: screenBounds.width, height: screenBounds.height)
tableView = UITableView(frame: rect, style: UITableViewStyle.plain)
tableView.dataSource = self
tableView.delegate = self
tableView.backgroundColor = UIColor.blue
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "my")
view.addSubview(tableView)
tableView.reloadData()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "my", for: indexPath)
cell.textLabel?.text = "This is row \(tableData[indexPath.row])"
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4//tableData.count
}
}
Wenn ich von Storyboard das Ziel Viewcontroller als meine erste vc bin Einstellung dann, wenn alles funktioniert fine.But Zugabe als Subview in Containeransicht Die cellForRowAt-Methode wird nicht aufgerufen, aber numberOfSection und numberOfRowsInSection werden aufgerufen.
Gibt es jemanden, der eine Lösung hat?
Sie müssen die UITableView zu Ihrem UIViewController.View hinzufügen –
Was ist die schnelle Version? – User511
reload tableview vor dem Hinzufügen zur Unteransicht – Jaydip