Reputation: 646
Im trying to have 2 tableview in a single view controller with one tableview being static while the other dynamic.
My view controller is set up like so
The top half being the static tableview.
i created ibOutlets for both tableViews but i can't seem to be able to customise the tables.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as UITableViewCell
//tableview2 is the dynamic tableView.
if (tableView == self.tableView2){
print("Tableview2")
}
else{
println("HELLLO")
}
return cell
}
i get the error * Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:6116 2014-10-23 22:31:52.246 Recipe app[2857:504809] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier cell2 - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'.
Upvotes: 0
Views: 2647
Reputation: 21536
Assuming you have given the prototype cells for your dynamic table the reuseIdentifier "cell2", move this line:
let cell = tableView.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as UITableViewCell
into either the if ...
clause, or the else ...
clause (whichever deals with the dynamic table). If tableView is the static table, it throws the error.
Upvotes: 0
Reputation: 19792
As error says you "must register a nib or a class for the identifier or connect a prototype cell in a storyboard".
Do this on viewDidLoad or awakeFromNib.
self.tableView.registerClass(UITableViewCell.classForCoder(), forCellReuseIdentifier:"cell2")
Or you have to make prototype cells in storyboard and give it "cell2" identifier
Upvotes: 1