【问题标题】:My tableview scrolling is very slow我的 tableview 滚动很慢
【发布时间】:2013-07-11 14:00:39
【问题描述】:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ 

static NSString *cellIdentifier=@"Cell";
MagazineListCell* cell=(MagazineListCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil)
{
    NSArray *arr=[[NSBundle mainBundle]loadNibNamed:@"MagazineListCell" owner:nil options:nil];
    cell=(MagazineListCell *)[arr objectAtIndex:0];
    [cell setDelegate:self];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}

NSMutableArray *arr=[[NSMutableArray alloc]init];
NSInteger startIndex;
NSInteger endIndex;

if(isLandscape)
{
    startIndex=indexPath.row*3;
    if (startIndex+3>[self.arrMagazine count ])
    {
        endIndex=[self.arrMagazine count];
    }
    else
    {
        endIndex=startIndex+3;
    }
}
else
{
    startIndex=indexPath.row*2;
    if (startIndex+2>[self.arrMagazine count])
    {
        endIndex=[self.arrMagazine count];
    }
    else
    {
        endIndex=startIndex+2;
    }
}
for (int x=startIndex; x<endIndex; x++)
{
    [arr addObject:[self.arrMagazine objectAtIndex:x]];
}
[cell setSelectedIndex:btnSegment.selectedSegmentIndex];
[cell contentForTableViewCell:arr setUIMode:isLandscape] ;
arr=nil;
return cell;

}

【问题讨论】:

  • 您是否进行了任何分析以找出花费时间的原因?
  • 为什么不在 willRotateToIntefaceOrientation 方法中保留 if-else 条件代码?在这里,每次重新加载表格时都会不必要地调用它,即使它的方向相同。
  • 将您的逻辑放在 cellForRowAtIndexPath 中不是一个好主意,我可以知道您将如何以及何时访问存储在单元格中的数据...

标签: ios performance uitableview


【解决方案1】:

检查您的重用标识符是否已设置,因为您可能每次都在创建单元格。

主要问题可能是您每次创建的数组,循环填充然后传递到单元格。您应该在需要之前尝试完成所有这些设置。

【讨论】:

  • 循环对于 myapp 来说是 imp 因为我有段控制并且必须为每个新视图加载表
  • @wain...我已经完成了分析并在索引路径上显示单元格的错误的行
  • 分析显示了什么,因为这是事实,而我们目前正在做的是有根据的猜测......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多