UITableView错误 ‘unable to dequeue a cell with identifier Cell'
2015-08-13 10:33
483 查看
- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier; - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0); // newer
1 第二个方法在SDK5.0是运行不起来的。
2 如果需要使用这个方法,你必须使用配套的方法来一起用,下面两个配套方法:
1 // Beginning in iOS 6, clients can register a nib or class for each cell. 2 // If all reuse identifiers are registered, use the newer -dequeueReusableCellWithIdentifier:forIndexPath: to guarantee that a cell instance is returned. 3 // Instances returned from the new dequeue method will also be properly sized when they are returned. 4 - (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(5_0); 5 - (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
注意看上面的注释
3 比如你已经用NIB做了一个Cell,或者自定义了一个Cell。我们在你创建UITableView的时候,就可以顺带
1 self.tableView.backgroundColor = xxxx; 2 [self.tableView registerClass:[CustomCell class] forCellReuseIdentifier:@"CustomCell"];
这样你在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
这个方法里,你就可以省下这些代码:
1 static NSString *CellIdentifier = @"Cell"; 2 if (cell == nil) { 3 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 4 //设置你的cell 5 }
而只需要
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
相关文章推荐
- 【工作笔记0008】easyui中datagrid绑定到table的翻页注意事项
- IOS的UINavigationController使用
- iOS编程——通过UUID和KeyChain来代替Mac地址实现iOS设备的唯一标示(OC优化版)
- query插件中(function ( $, window, document, undefined )的作用
- 《android---获取值AndroidManifest.xml中meta-data的value》
- android stuio中assets文件夹在哪里?
- 黑马程序员--java技术blog---第七篇:GUI
- 滑动文本标签,一个类解决广告轮播 UIScrollView
- Qt Quick 版本
- 连接池 druid(阿里巴巴的框架)
- iOS 9 之New UIKit for International User Interfaces
- 在pycharm中运行代码时提示错误信息 “ValueError: need more than 1 value to unpack”处理方法
- Beeline known issues
- IOS:UILbalel笔记
- Advanced Fruits(好题,LCS的模拟)
- 【CSS3 入门教程系列】CSS3 Media Queries 实现响应式设计
- iOS基础-UIKit框架-多控制器管理-项目常用文件,4大对象,程序启动原理
- UIVIEW 的旋转与缩放以及同时应用两种效果(一)
- ExtJs DOM操作(与jQuer
- iOS开发之使用Storyboard预览UI在不同屏幕上的运行效果