0
I own a UITableView
simple. It is loaded from a .nib
and added as a subview
, it appears, loads the data, presents the same everything correctly, but from the moment I select a cell, the data simply vanishes.
I’m currently using Swift, but I’ve had this same problem with Objective-C, which was solved without any code change, but now it is no longer being resolved.
Follow the creation code of UITableView
:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
listObjectsToList = ["String 1","String 2","String 3"]
self.view.frame.size = CGSizeMake(300, 110)
self.view.layer.cornerRadius = 5
self.view.layer.masksToBounds = true
self.tableView.scrollEnabled = false
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return listObjectsToList.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell
cell.textLabel.text = listObjectsToList.objectAtIndex(indexPath.row) as? String
return cell
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 40
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.tableView.deselectRowAtIndexPath(indexPath, animated: true)
let objectSelected: AnyObject = listObjectsToList.objectAtIndex(indexPath.row)
object.type = objectSelected as String
self.view.removeFromSuperview()
}
Addition code as subview
:
var listTypeTableViewController = NSBundle.mainBundle().loadNibNamed("TableViewTypeScheduling", owner: self, options: nil)[0] as ListTypeTableViewController
listTypeTableViewController.view.frame = CGRectMake(10, 80, 300, 130)
self.view.addSubview(listTypeTableViewController.view)
It is worth mentioning that the method didSelectRowAtIndexPath
is not called
Why do you claim that the method
didSelectRowAtIndexPath
is not called? It will not be called if you have not defined the delegate of the table, was it? Because in this method you are removing all the view (and in it contains the table), that would be exactly the problem.– Paulo Rodrigues
I put a breakpoint, it is not called and the view is not removed from the screen. The class is a Uitableviewcontroller
– Gian