【发布时间】: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