Custom CellIdentifier is Null When Using Search Display Controller Custom CellIdentifier is Null When Using Search Display Controller xcode xcode

Custom CellIdentifier is Null When Using Search Display Controller


As of here search display controller question, you need to access the self.tableView instead of tableView:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CellId"];    // do your thing    return cell;}


For those using iOS 5 and StoryBoards, you would want to use the following method instead of initWithIdentifier:

initWithStyle:(UITableViewCellStyle)stylereuseIdentifier:(NSString *)reuseIdentifier

Example:

  NSString *cellIdentifier = @"ListItemCell";  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];  if (cell == nil) {    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];  }


I'm not sure about how this should work in storeboarding.

But normally you would check if the [tableView dequeueReusableCellWithIdentifier:CellIdentifier] returns a cell.Because if the cell in not loaded before or there aren't any cells to reuse you will have to create a new cell:

SpeakerCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];if (cell == nil) {   cell = [[SpeakerCell alloc] initWithIdentifier: CellIdentifier];}

Also when in declaring local variables in Objective-C we tent not to capitalize the first letter.