Iβve been scratching my head over this problem for two days, and I really canβt find out why this behavior is happening ... It really makes me sick!
I have an iOS application that uses storyboards built using the interface builder. There are 2 tabs in the opened TabBarVC view:
Tab 1: Navigation Controller -> TableView Controller1 -> TableView Controller2
Tab 2: Collection view controller β Navigation controller β TableView Controller3 β TableView Controller2 (yes, I wanted to write this)
In each of the TableView 1 and 3 controllers, I use dynamic prototyped cells (style = right detail, accessory = disclosure indicator). In the first, I set the reuse identifier, say TableView1Cell. In my implementation of tableview, I use the following code to return the cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"TableView1Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; SFBottles *bottleAtIndex = [self.dataController getCellarBottleAtIndex:indexPath.row]; [cell.textLabel setText:bottleAtIndex.houseName]; [cell.detailTextLabel setText:bottleAtIndex.productName]; return cell; }
... and I use the following code to go to TableView Controller2:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"ShowBottleDetails"]) { CellarDetailViewController *detailVC = [segue destinationViewController]; detailVC.bottle = [self.dataController getCellarBottleAtIndex:[self.tableView indexPathForSelectedRow].row]; } }
All of the above works as expected. I am doing the same in TableView Controller3:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"TableView3Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; SFBottles *bottleAtIndex = [self.bottlesArray objectAtIndex:indexPath.row]; [cell.textLabel setText:bottleAtIndex.houseName]; [cell.detailTextLabel setText:bottleAtIndex.productName]; return cell; }
... and when this view controller loads at runtime, I get the following error:
Application termination due to the uncaught exception "NSInternalInconsistencyException", reason: "it is impossible to disconnect the cell with the identifier TableView3Cell - must register a thread or class for the identifier or connect the cell prototype in the storyboard
However, I was able to clear this error by adding this line to the TableView Controller3 viewDidLoad:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"TableView3Cell"];
But when I do this, neither the subtitles on the right nor the disclosure indicator are displayed on the displayed cells.
In addition, selecting a cell does not cause a similar segue, even if the code is the same as in the implementation of TableView Controller1:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"OverviewListToBottleDetails"]) { CellarDetailViewController *detailVC = [segue destinationViewController]; detailVC.bottle = [self.bottlesArray objectAtIndex:[self.tableView indexPathForSelectedRow].row]; detailVC.navigationItem.rightBarButtonItem = nil; } }
So, why are two similar TableView controllers using the same cells and the same for the same controller not behaving the same?
I know that this is a lot of information, ask your questions and I will answer as soon as possible.
Thanks!