0
votes

I have a tableViewController with a search bar and a search display controller.

That main tableViewController's tableView has a prototype cell defined on storyboard.

I am having crashes on the line

   FileManagerTableViewCell *cell = (FileManagerTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

when the search tableview is about to be displayed. Apparently the search tableView cannot access the prototype cells defined on the main tableView on storyboard.

How do I make the search tableview access the prototype cell defined for the main tableview on storyboard?

2

2 Answers

0
votes

If you want both tables to use the same cell, you should design that cell in a xib file instead of in the storyboard. Have both tables register the nib, using registerNib:forCellReuseIdentifier:.

0
votes

The answer to this is simple to edit but complex to understand why Apple created something half-cooked like that. The solution comes from the first comment of this answer

The answer is to use self.tableview instead of tableview.

   FileManagerTableViewCell *cell = (FileManagerTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];

The explanation: when a search starts, iOS switches to show the search tableview but that tableView has no prototype cells, so this line

   FileManagerTableViewCell *cell = (FileManagerTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

is asking iOS to dequeue a cell from the search tableView. By using self.tableview, you are saying to dequeue a cell from the main tableView, that contains a prototype cell defined on storyboard.

I hope one day iOS APIs are designed to make our lives easy, thing that is far from happening today.