【问题标题】:I uitableview the (cell = nil) always not call?我uitableview (cell = nil) 总是不调用?
【发布时间】:2016-10-12 10:39:49
【问题描述】:

在 ui tableview 单元格中, 语句 if (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];
}

}

【问题讨论】:

    标签: ios tableviewcell


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      @987654321@ 在使用 Storyboard 时总是返回一个单元格。

      【讨论】:

        【解决方案3】:

        使标识符不是固定值

        将其设为 index.row(转换为字符串作为标识)

        你的错误可能是细胞垃圾箱

        【讨论】:

          猜你喜欢
          • 2015-09-17
          • 2012-09-29
          • 1970-01-01
          • 2015-10-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-05-29
          • 1970-01-01
          相关资源
          最近更新 更多