ios - 基于 UITableView ios 中的可见单元格加载内容

标签 ios objective-c uitableview asynchronous nsmutablearray

在我的应用程序中,我试图加载一个 NSMutableArray,其中包含总共 80,000 个文本“名称”,并且它工作正常,但是当我们滚动整个滚动条时会出现滞后(滚动不流畅)。

所以我正在寻找任何方法将内容仅加载到 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;

}

请帮助我滚动此列表。

最佳答案

假设 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 项的查找,并只获取一项的 Name 属性。同样:

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

可以替换为:

return [bigArray count];

关于ios - 基于 UITableView ios 中的可见单元格加载内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26774266/

相关文章:

cocoa - 安装 IOS 后,NSSize 和 NSPoint 是否在 XCode 3.2.3 中工作?

ios - 引用泛型类型 'Map' 需要 <...> 中的参数 - Swift

ios - 如何创建一个像 UILabel 一样具有 intrinsicContentSize 的 View ?

ios - 导入和 UIAlertView

objective-c - 路径上的矩形碰撞检测

android - ios和android推送通知到多个设备

iphone - 如何获得 objective-c 中两个位置之间的距离(以英里为单位)?

iphone - tableView :sectionForSectionIndexTitle:atIndex:? 到底有什么意义

ios - 如何在 Swift 中以编程方式创建包含部分的分组 TableView

ios - 无法使用 Swift 语法过滤器