UITableView代理cellForRowAtIndexPath不执行的相关解决方案
2016-07-05 21:16
447 查看
UITableView代理cellForRowAtIndexPath不执行的相关解决方案
今天写一个程序,郁闷了半天,结果tableView总是不执行cellForRowAtIndexPath这个方法,一开始真不知道为什么,TableView一直显示不正确,最后调试了半天,终于明白,原来是numberOfRowsInSection返回失败的原因,主要原因是由于在ViewAppDelegate代理中未对数据库进行初始化,原因终于找到了,还是比较高兴!
总结:如果发现TableView总是显示不正确,或没有显示,则需要跟踪看看下面的函数是否返回正确
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
1、是否设置代理与数据源
[table setDelegate:self];
[table setDataSource:self];
2、numberOfSectionsInTableView是否设置
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
3、numberOfRowsInSection方法返回值是否正确,如果不正确就不会执行 cellForRowAtIndexPath。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
4、检查Table是否被其他View遮挡
5、还有可能是autolayout引起的,autolayout约束不对,也会导致tableview显示不出来,
cellForRowAtIndexPath是在显示到界面的时候才调用,正确的设置autolayout就会执行该方法。
相关文章推荐
- poj1776Task Sequences【竞赛图的哈密顿路径】
- [UE4教程] 图形学基础教程01--渲染管线 (带演示程序)
- sqlserver -- 解决sqlserver2008“Prevent saving changes that require table re_creation(阻止保存要求重新创建表的更改)”的问题
- 1443. Printer Queue
- UITableViewHeaderFooterView 特点
- 1002.Anti-prime Sequences
- 导入pullloadmorerecyclerview库出现错误:Please configure your build for VectorDrawableCompat
- leetcode 334. Increasing Triplet Subsequence
- ORA-00054: resource busy and acquire with NOWAIT specified
- MQTT(使用mosquitto做broker)做Android推送部分总结
- Implement Queue using Stacks
- 台式机安装系统时区分BIOS与UEFI
- 232. Implement Queue using Stacks
- android example 1_UI
- 新增Tao插件,Red Giant 经典特效插件 Trapcode Suite 13 for Win/Mac
- @RequestBody 和@ResponseBody 注解详解
- 使用android SpannableStringBuilder实现图文混排,查看更多
- wait_queue_head_t和wait_queue_t
- UE4 学习笔记(1)——如何用VS进行UE4的Debug
- Guice入门