为原型单元格更改了dequeueReusableCellWithIdentifier行为?

Ari*_*ior 9 iphone cells storyboard tableview ios5

在iOS5中,在故事板上使用ARC和原型单元格用于tableView,我可以替换下面的代码:

static NSString *CellIdentifier = @"Cell";

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

// Configure the cell...
return cell;
Run Code Online (Sandbox Code Playgroud)

有了这个简单的代码??:

UITableViewCell *cell = [tableView 
  dequeueReusableCellWithIdentifier:@"Cell"];
return cell;
Run Code Online (Sandbox Code Playgroud)

我在这个链接上看到了这个:

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

提前致谢!

Arildo

Kap*_*ppe 8

当然,你的代码是正确的,故事板自动分配新的单元格,这段代码工作得很好:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{   
    RoadbookCell *cell = (RoadbookCell *)[tableView dequeueReusableCellWithIdentifier:@"RoadbookCell"];

    //Configure cell
    //[cell.lab1 setText:@"Test"];

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

  • 并且记住你应该在"awakeFromNib"方法中的单元子类中进行任何设置,而不是"initWithStyle:"(它不会被调用),因为它从故事板加载. (2认同)