基于UITableView ios中的可见单元格加载内容
在我的应用程序中,我试图加载一个NSMutableArray,总共有80000个文本“name”,它工作得很好,但是当我们滚动整个滚动时,会出现延迟(不是平滑滚动) 因此,我正在寻找任何方法,只将内容加载到UITableView中的可见单元格中(以异步方式) 这是我当前的代码基于UITableView ios中的可见单元格加载内容,ios,objective-c,uitableview,asynchronous,nsmutablearray,Ios,Objective C,Uitableview,Asynchronous,Nsmutablearray,在我的应用程序中,我试图加载一个NSMutableArray,总共有80000个文本“name”,它工作得很好,但是当我们滚动整个滚动时,会出现延迟(不是平滑滚动) 因此,我正在寻找任何方法,只将内容加载到UITableView中的可见单元格中(以异步方式) 这是我当前的代码 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; //count of section }
- (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;
}
请帮助我滚动此列表。如果您的大数组已加载,则表示数组已完全准备就绪,或者没有后台任务正在运行,则滚动应该很快。检查一些额外的东西不会像加载其他东西或任何后台任务那样影响滚动?由于UITableView只加载可见单元格,因此不能是tableView使您速度变慢。但由于NSArray并不是真正最快的访问结构之一,因此可能是阵列使您的速度变慢了。您是否尝试过将数据拆分为几个较小的数组(例如,始终将10k值拆分为一个数组),并根据indexPath.row实现一些逻辑来访问不同的数组
哦,顺便问一下:你在测试什么设备?假设bigArray就是它所说的,即NSArray,那么这行:
cell.textLabel.text=[[bigArray valueForKey:@"Name"] objectAtIndex:indexPath.row];
也许是什么让你慢下来了。[bigArray valueForKey:@“Name”]
会扫描所有80000个条目,并获取和存储valueForKey。只有这样,才能选择正确的行。我会把它们转过来:
cell.textLabel.text=[[bigArray objectAtIndex:indexPath.row] valueForKey:@"Name"];
这样,只需查找800000个项目,并仅获取一个项目的Name属性。同样地:
return [[bigArray valueForKey:@"Name"]count];
可替换为:
return [bigArray count];
UITableView仅加载可见单元格。不要一次通过80K记录。冷却它的工作..非常感谢..我将对我的所有表做相同的更改