Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I looked in your project:</p> <pre><code>NSLog(@"%@", cell.name.text); // null </code></pre> <p>Because cell.name is nil. The explanation is: then you load your normal tableView, the cell "LocalCell" is loading from Storyboard, allocating and initialising your labels, but then you using self.searchDisplayController.searchResultsTableView you initialise "LoadCell", but never initialise his labels (because they are weak IBOutlets - and used in storyboard).</p> <p>To solve your problem, I found 3 solutions: 1. Create another SearchCell with strong references to his UILabels, initialise all UILabel s in -(id)init of SearchCell. Then use it in your controller.</p> <pre><code>[self.searchDisplayController.searchResultsTableView registerClass:[SearchCell class] forCellReuseIdentifier:@"SearchCell"]; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; static NSString *SearchCellIdentifier = @"SearchCell"; Restaurant *res; if (tableView == self.searchDisplayController.searchResultsTableView) { SearchCell *cell = [tableView dequeueReusableCellWithIdentifier:SearchCellIdentifier forIndexPath:indexPath]; if (!cell) { cell = [[SearchCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } res = (Restaurant *)self.searchResults[indexPath.row]; cell.nameLabel.text = res.name; cell.descLabel.text = res.desc; // image load return cell; } else { LocalCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; if (!cell) { cell = [[LocalCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } res = (Restaurant *)self.restaurants[indexPath.row]; cell.nameLabel.text = res.name; cell.descLabel.text = res.desc; // image load return cell; } } </code></pre> <p>Another way is to create a nib with your cell "SearchCellNib", and use your created LoadCell class. For load nib use:</p> <pre><code>cell = (LoadCell*)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = (LoadCell*)[[[NSBundle mainBundle] loadNibNamed:@"SearchCellNib" owner:nil options:nil] objectAtIndex:0]; } </code></pre> <p>Or use UITableViewCell</p> <pre><code>UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SearchCellIdentifier forIndexPath:indexPath]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; } res = (Restaurant *)self.searchResults[indexPath.row]; cell.textLabel.text = res.name; cell.detailTextLabel.text = res.desc; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload