The background
I have an iPhone app that makes use of a UITableViewController
sub class in several places by sub classing again for each use. One of those uses is a search controller.
@interface TableViewController : UITableViewController
// ...
@interface SearchTableViewController : TableViewController <UISearchDisplayDelegate, UISearchBarDelegate>
In the storyboard editor I have the same table view, cell structure, and reuse identifier in each view that makes use of TableViewController
. Everywhere I am using it the storyboard is generating cells for me based on my design time prototypes so that in the tableView:cellForRowAtIndexPath:
method I don't have to include the if (cell == nil)
section.
The problem
I have done something wrong and my search controller's cells aren't being generated by the storyboard like the others. At first, I added in the if (cell == nil)
bit to solve the problem but it causes my search to display blank rows. Actually, the search shows the correct number of blank rows. After you cancel the search, the results appear from out of the background. Here's the code from TableViewController
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
ModelObject* obj = [self.dataSource modelAtIndex:indexPath.row];
UILabel* name = (UILabel*) [cell viewWithTag:1];
name.text = obj.name;
return cell;
}
I suspect there may be other details necessary to identify the issue but any tips on what kinds of things could cause this would be helpful. Thanks.