UITableView Controller报错解决方法
来源:互联网 发布:sql do while的用法 编辑:程序博客网 时间:2024/04/30 23:36
TableView
报错解决方案与解释
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
未注册Cell,凡5.1版本起的xcode,纯代码写tableview,都要给返回的cell注册,无论是系统的还是自定义的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { <span style="color:#009900;"> static NSString *CellIdentifier = @"Cell"; </span><span style="color:#ff0000;"> [self.tableView registerClass:[</span><span style="color:#3366ff;">UITableViewCell</span><span style="color:#ff0000;"> class] forCellReuseIdentifier:CellIdentifier]; </span> UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } // config cell ... return cell; }
绿色部分代码是标识cell,建议放到viewdidload方法上面;
红色部分代码则是注册cell,建议放到viewdidload方法里面,第一次进入页面就会注册cell 而不用每次返回 cell 去注册.
蓝色部分UITableViewCell是系统自带的cell,如果自定义cell也需要注册,把UITableViewCell改为自定义的cell类名即可;
0 0
- UITableView Controller报错解决方法
- rails generate controller报错
- UITableView加入TableFooterView报NSRangeException异常—-解决方法
- UITableView中Cell报错[UITableView _configureCellForDisplay:forIndexPath:]
- 报错'An instance 0x7fb441883000 of class UITableView was deallocated while key value observers we 解决方法
- spring mvc Controller重复导致报错
- Swift UITableView遵从UITableViewDataSource报错问题
- linux报错解决方法
- 报错信息 解决方法
- 127报错解决方法
- sidekiq报错 解决方法
- MyEclipse_ServerView报错解决方法
- AfxGetInstanceHandle()报错解决方法
- vs报错解决方法
- uiautomatorviewer报错解决方法
- 报错的解决方法
- MySQL 报错解决方法
- struts报错和解决方法
- JavaScript——BOM(浏览器对象模型),时间间隔和暂停
- Android Studio Gradle相关异常记录
- HDU 1060 Leftmost Digit
- Activity常用控件——09
- hdu-1166
- UITableView Controller报错解决方法
- 【Cocos2d-x3.0学习笔记 07】游戏时间到LitterRunner02
- 程序员面试宝典递归的求解字符串长度
- 理解事务的隔离性(转载)
- 面试经历
- think in java读书笔记--字符串小细节
- 在现有Windows电脑安装Ubuntu 10.04 LTS记录
- Apache service monitor下无服务可供启动
- [LeetCode]ReverseInteger