2016-06-11 63 views
0

在ui tableview单元格中, 语句if(cell == nil)未被调用。我uitableview(cell = nil)总是不会调用?

因为当我初始化if语句之外的单元格时,talbe在错误的行中会有一些错误的标签。

我该如何初始化我的细胞?

@“tttestttt”NS LOG并不是所有的表创建时。

- (UITableViewCell的*)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *MyIdentifier = @"GroupsCell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
if (cell == nil) { 
    NSLog(@"tttesttttt"); 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]; 
} 

}

回答

1

使用更方便的方法dequeueReusableCellWithIdentifier:forIndexPath:它总是返回一个有效的单元格。

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

    ... 

    return cell; 
} 
0

做出标识不是一个固定值

使其作为index.row(转换为字符串作为身份)

你的错误可能是由电池箱垃圾

相关问题