TableView 性能问题

wmmj23 发布于 2013年09月12日 | 更新于 2013年09月12日
无人欣赏。

我在cellForRowAtIndexPath方法第一行和return cell之前nslog了一下。中间创建了自己cell。并没有block代码。
通过log我看到在第一个cell return 到第二个cell创建之前有较大一段时间。
界面上的显示就是第一条cell很快显示,后面的cell等了一小会儿才显示。
请问这是怎么一回事?cellForRowAtIndexPath方法return一个cell以后做了些什么呢?谢谢

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
static NSString *CellIdentifier = @"First Table View";
FirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];

// Configure the cell...
NSLog(@"before cell");
int sum =0;
for (Categories *ca in self.list) {
    sum +=[ca.count intValue] ;
}

if (indexPath.row ==0) {

    [cell setcaNil:sum];

}else{

    Categories *ca = [self.list objectAtIndex:indexPath.row -1];
    [cell setCa:ca];

}
NSLog(@"after cell");

return cell;
        }

日志打印的时候:
2013-09-12 17:05:31.565 Info[1252:c07] before cell
2013-09-12 17:05:31.567 Info[1252:c07] after cell
2013-09-12 17:05:31.785 Info[1252:c07] before cell
2013-09-12 17:05:31.786 Info[1252:c07] after cell
2013-09-12 17:05:31.787 Info[1252:c07] before cell
2013-09-12 17:05:31.788 Info[1252:c07] after cell

第二个before cell 和第一个after cell之间差0.2秒 而后面就没事了
在模拟器上这个时间差不算什么 在真机上就很明显
我知道肯定是我哪儿有问题 可是这之间应该什么都没有做啊
找不到应该在哪里
真机上 有时候能差几秒:
2013-09-12 17:28:59.863 Info[6542:907] before cell
2013-09-12 17:28:59.866 Info[6542:907] after cell
2013-09-12 17:29:04.318 Info[6542:907] before cell
2013-09-12 17:29:04.319 Info[6542:907] after cell

共8条回复
tinyfool 回复于 2013年09月12日

你说得太不明白了,还有你代码做了什么你都没有说明白,性能不用担心系统有问题,慢,肯定是你哪里做错了

threeknife 回复于 2013年09月12日

你不用关心的系统做了什么 肯定是你代码写的有问题 可以把 cellforrow的方法贴一下

wmmj23 回复于 2013年09月12日

@tinyfool @threeknife 我贴了代码 不知道说的能不能清楚点儿 谢谢

tinyfool 回复于 2013年09月12日

3楼 @wmmj23 你这是完全的代码么?

怎么没有创建cell的代码,都是复用来的?

threeknife 回复于 2013年09月12日

3楼 @wmmj23 你要取得复用view后 还要判断view 是否有效存在呢
tiny 说的对啊 创建cell的代码在哪?

wmmj23 回复于 2013年09月12日

5楼 @threeknife 4楼 @tinyfool

嗯,没有创建cell 都是复用来的 加了判断是否是nil 也是一样的

terryso 回复于 2013年09月12日

6楼 @wmmj23 你根本就没有创建过Cell,哪来的复用啊?

wmmj23 回复于 2013年09月12日

7楼 @terryso 我在storyboard中设了id和cell子类 然后dequeueReusableCellWithIdentifier 取的啊

我在cell取完以后打印cell 会出现以下不一样的:
b0x75624b0; aseClass = UITableViewCell; frame = (0 0; 320 44); 。。。
第二个cell打印是
0x75624b0; baseClass = UITableViewCell; frame = (0 0; 320 44); hidden = YES; autoresize = W; 。。。
以后又恢复第一个样子 就是内存地址不一样了

登录 或者 注册
相关帖子