Search code examples
iphoneobjective-cios5automatic-ref-countinguistoryboard

Does dequeueReusableCellWithIdentifier work with ARC?


In iOS5, using ARC and prototype cells for tableView on storyboard, can I replace the code below:

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView 
  dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleDefault 
      reuseIdentifier:CellIdentifier];
}

// Configure the cell...
return cell;

With this simple code?:

UITableViewCell *cell = [tableView 
  dequeueReusableCellWithIdentifier:@"Cell"];
return cell;

I saw this on this link:

http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

Thank's in advance!


Solution

  • This problem is happening because you aren't creating the MenuViewController from the storyboard. You are creating it like this:

    MenuViewController *menuViewController = [[MenuViewController alloc] init];
    

    That instance of MenuViewController isn't connected to the storyboard, so it doesn't know about the prototype cells in the storyboard.

    You need to go into your storyboard and set the identifier of the MenuViewController there to something like menuViewController. Then you can create an instance like this:

    MenuViewController *menuViewController =  [self.storyboard instantiateViewControllerWithIdentifier:@"menuViewController"];