2016-06-11 80 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(轉換爲字符串作爲身份)

你的錯誤可能是由電池箱垃圾

相關問題