2014-11-06 73 views
0

在我的应用程序中,我试图加载一个总共80,000个文本“名称”的NSMutableArray,其工作完美,但当我们滚动整个滚动得到滞后(不平滑滚动)。基于UITableView中的可见单元格加载内容ios

所以我正在寻找任何方式将内容加载到UITableView中的可见单元格(以异步方式)。

这是我当前的代码

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; //count of section 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    // return [[copyGenericDetails valueForKey:@"name"]count]; //count number of row from counting array hear cataGorry is An Array 

    return [[bigArray valueForKey:@"Name"]count]; 
} 



- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *MyIdentifier = @"cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
             reuseIdentifier:MyIdentifier]; 
    } 


    cell.textLabel.text=[[bigArray valueForKey:@"Name"] objectAtIndex:indexPath.row]; 
    return cell; 
} 


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    return 40; 

} 

请帮我这个列表的滚动。

+1

的UITableView加载唯一可见的细胞:

return [[bigArray valueForKey:@"Name"]count]; 

可以替换。不要一次传递80K记录。 – BhushanVU 2014-11-06 07:56:50

回答

2

假设bigArray是什么,是说,即NSArray的,那么这行:

cell.textLabel.text=[[bigArray valueForKey:@"Name"] objectAtIndex:indexPath.row]; 

可能是什么放慢你失望。 [bigArray valueForKey:@"Name"]会导致扫描所有80,000个条目,并获取并存储valueForKey。只有这样你才能选择正确的行。我想整开关它们:

cell.textLabel.text=[[bigArray objectAtIndex:indexPath.row] valueForKey:@"Name"]; 

这样,它只是在80,0000物品查找,并获得名称属性只是一个项目。同样:

return [bigArray count]; 
+0

很酷的工作..感谢alot ..我会做同样的改变我所有的表 – 2014-11-06 09:20:57

0

如果你的大数组被加载意味着数组完全准备好或没有后台任务正在运行,那么滚动应该是快的。检查一些额外的东西是不是像加载其他东西或任何后台任务一样影响滚动?

0

由于UITableView只加载可见单元格,因此它不能是减慢速度的tableView。但是由于NSArray实际上并不是最快的访问结构之一,它可能会让阵列变慢。你有没有尝试将你的数据分成几个较小的数组(可以说总是将10k值放入一个数组中)并根据indexPath.row实现一些逻辑来访问不同的数组?

哦,顺便说一句:你在测试什么设备?

+0

iphone 5s ...... – 2014-11-06 09:19:52

相关问题