2013-09-23 54 views
1

最近我注意到当我们创建一个新的Class模板时,(UcodeableViewController实现的子类中的Xcode - > File - > New - > File)在cellForRowAtIndexPath方法中是部分的。我粘贴下面的方法。在UITableViewController模板中缺少TableViewCell分配

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    // Configure the cell... 

    return cell; 
} 

我认为像报表(其中缺失),

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

是必须实施。这是一个错误还是别的?

回答

1

如果您使用方法registerNib:forCellReuseIdentifier:registerClass:forCellReuseIdentifier:在表格视图中注册单元格,或者在xib或故事板中的表格视图中创建单元格,则不需要创建单元格。