测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | BSD 3.0 |
发布最后发布 | 2015年3月 |
由 Alberto De Bortoli 维护。
ADBBackgroundCells 允许为在后台执行长时间任务而不会阻塞 UI 的 UITableViewCell 对象进行懒加载。使用 NSInvocationOperation 代替 GCD (Grand Central Dispatch),在 NSOperationQueue 对象中放置的操作可以取消。这种线程模式允许优化长滚动,当显示很多单元格并且立即重新使用/消失时,无需执行不再可见的单元格的任务。ADBBackgroundCells 基于 block 并使用 Objective-C 运行时。
如果您想使用 CocoaPods (https://cocoapods.org.cn/) 将此组件作为 pod 包含,只需将以下行添加到 Podfile 中:pod "ADBBackgroundCells"
尝试包含的示例项目。
使用方法
UITableViewCell+Background.{h|m}
和 UITableView+Background.{h|m}
复制到您的项目中UITableView+Background.h
和 UITableViewCell+Background.h
tableView:cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuseCellId = @"reuseCellId";
MyUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseCellId];
if (!cell) {
cell = [[MyUITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseCellId];
}
NSMutableDictionary *info = [NSMutableDictionary dictionary];
[cell addBackgroundBlock:^{
// long time job performed on a background thread
...
[info setObject:@"Long job output" forKey:@"output"];
} callbackBlock:^(id cell){
MyUITableViewCell *c = (MyUITableViewCell *)cell;
// callback to update the UI
c.textLabel.text = [info objectForKey:@"output"];
...
} usingQueue:tableView.operationQueue];
return cell;
}
viewDidLoad
方法或包含表格视图的控制器的设计ated 初始化器)中创建一个 NSOperationQueue
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.operationQueue = [[NSOperationQueue alloc] init];
self.tableView.operationQueue.maxConcurrentOperationCount = 1;
...
}
根据新的 BSD 许可证许可。
版权 (C) 2012, Alberto De Bortoli。保留所有权利。
在不违反以下条件下,允许以源代码形式和二进制形式重新分发和使用,无论是修改还是未修改:* 源代码再分发必须保留上述版权声明、本条件列表和以下免责声明。* 二进制形式再分发必须以文档和/或其他随分发提供的材料的形式复制上述版权声明、本条件列表和以下免责声明。* 不得未经Alberto De Bortoli的特定先前书面许可使用Alberto De Bortoli 的名字或其贡献者的名字 endorse 或推广根据本软件衍生出的产品。
本软件按“原样”提供,明示或暗示的任何保证,包括但不限于适销性和针对特定目的的适用性的暗示保证均予以排除。在任何情况下,Alberto De Bortoli 承担任何直接、间接、偶然、特殊、示范性或后果性的损害(包括但不限于替代品、数据、收益或业务中断),无论基于何种理论(合同、严格责任或侵权,包括疏忽或不作为),均不承担责任,即使被告知可能的此类损害。
信息可以在我的网站上找到 http://www.albertodebortoli.it、Twitter 上。