cell重用时,老是提示找不到标识的cell,让我们注册cell
2016-01-05 00:00
676 查看
摘要: 1、当我们重用cell的时候,老是报错,提示我们找不到cell的标识2、事实上,我们已经写了判断语句(如果在缓存池中找不到cell的话,就重新创建cell)报错提示:[9098:232849] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:65642016-01-05 00:00:37.574 UI进阶考试—微信[9098:232849] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier mineCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {// 创建可重用的cellUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];if (cell == nil) {cell = [[UITableViewCell alloc] init];}return cell;}注意:上面的代码出错原因: 1.没有给storyboard中的cell添加标识。 2.如果是纯代码创建的UIStoryboard,在重用cell的时候,应该使用方法
- (nullable __kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier;解决方法一:在storyboard中给cell添加标识,如果使用这种方法的话,就可以不用判断cell是否能从缓存池中找到,因为当从缓存池中找不到的话,就会使用storyboard中的cell。解决方法二:cell重用的时候,使用方法
- (nullable __kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier;再加上if判断
if (cell == nil) {cell = [[UITableViewCell alloc] init];}当从缓存池中找不到cell的时候,就会if判断语句的代码中重新创建。总结:1、如果我们是用纯代码创建的UITableViewController的话,这时要创建可重用的cell的时候,一定要判断是否能从缓存池中找到,否则就会报错的!2、如果是在stroryboard中直接以拖拽的方式,创建的UITableViewController的话,最好给storyboard中的cell添加一个标识,以防出错。标识后我们就没必要再去判断cell是否能从缓存池中找到,因为即使找不到,系统也会自动的加载storyboard中的cell的。
相关文章推荐
- Android中的Bitmap缓存池使用详解
- tableView的重用机制
- go语言的官方包sync.Pool的实现原理和适用场景
- iOS 的tabelView 重用机制 缓存池
- 对xib构建的UITableViewCell的重用方法和代码添加约束的方法 学习笔记
- ios学习笔记UITableViewCell重用时出现重影的解决方案
- IOS Table中Cell的重用reuse机制分析
- TableView的重用机制
- 在tableviewcell 加载图片,解决第三方SDWebImage网络不是很通畅的状态下往下拉不能加载图片
- 解决UITableView中Cell重用机制导致内容出错的方法总结
- 解决UITableView中Cell重用机制导致内容出错的方法总结
- must register a nib or a class for the identifier or connect a prototype cell in a storyboard'的解决办法
- golang sync.Pool试用说明及注意事项
- redis客户端Jedis源码分析系列——从缓存池中获取资源和销毁资源
- iOS之TableViewCell重用机制避免重复显示问题
- dequeueReusableCellWithIdentifier vs dequeueReusableCellWithIdentifier : forIndexPath
- iOS开发 多个cell在初始化时注意重用池
- 不可变类
- 游戏设计 -- 资源缓存池
- unity 之 缓存池 基础篇