但是我改成把 cell 的 textLable 的 text 值存进数组,复用时取出来的就是正确的,有什么需要注意的地方吗 代码如下:
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * timeRing = @"ring";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:timeRing];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:timeRing];
    }else{
        while ([cell.contentView.subviews lastObject]!=nil) {
            [[cell.contentView.subviews lastObject] removeFromSuperview];
        }
    }
    cell.accessoryType = UITableViewCellAccessoryNone;
    
    if (self.cellArray.count<self.ringArray.count) {
  
        self.timeRingItem = self.ringArray[indexPath.row];
        cell.tintColor = [UIColor redColor];
        cell.textLabel.text= self.timeRingItem.ringName;
        [self.cellArray addObject:cell];
    }
    else{
    	cell = self.cellArray[indexPath.row];
    }
    
    return  cell;
}
|  |      1targz      2016-03-23 01:11:11 +08:00  1 1. cell 为 object ,你存入数组的为此 cell 的指针 2. 既然已经使用了`tableView`的复用,就不要自己存 cell 。假设页面可以显示 2 个 cell ,你就算有 100 个 cell ,实际上实例化的也大概只有 3 个 cell 。 也就是说,你的数组里是这样的[cell1, cell2, cell3, cell1, cell2, cell2.....] 3. 比较合理的方式就是使用 tableView 的 cell 复用。每次拿到 cell 或者实例化 cell 后,将对应的数据赋值即可。 | 
|  |      2codeisjobs OP @targz 感谢回答,懂了,原来是指针的问题,看来对指针还是不熟啊我 | 
|      3alexzuo      2016-03-23 08:16:12 +08:00 @codeisjobs 在公交上 车晃的比较厉害 没仔细看代码 感觉上不是你理解的指针问题 更像是一楼第二条所说的 cell 复用问题 | 
|  |      5codeisjobs OP @targz 对的,我没考虑到复用的 cell 的指针还是原来的那些,存到数组里结果指针指向的是复用前的对象,所以才会出现存字符串就正确。哎呀,感谢回答,解决了我的一个知识点 bug | 
|  |      6targz      2016-03-23 08:45:15 +08:00 via iPhone @codeisjobs 其实很简单,数据是值类型的,那就是值。对象类型的,就是指针。声明的时候加不加星号就能判断出来。 | 
|  |      7targz      2016-03-23 08:48:21 +08:00 via iPhone @codeisjobs 或者说,实现了 copy 协议的对象,你存一个 copy ,就是新的一个对象了。 | 
|      9artkernelzyc      2016-03-23 15:49:01 +08:00 @targz cell 复用有多少个,是根据 cell 高度来计算的,和 uitableview 的高度来计算得出的。 |