今天在学习UItableView 的时候,定义了一个属性

 @property (weak, nonatomic) NSMutableArray *dataList;

在ViewDidLoad方法方法中用一下方法实例化

  _dataList = [NSMutableArray arrayWithCapacity:];      

     for (NSInteger i = ; i < ; i++)     

 {       

       Book *book = [[Book alloc]init];                 

       NSString *string = [NSString stringWithFormat:@"iOS进阶(%ld)", i];        

      [book setBookName:string];         

      [book setPrice:98.98];                  

      [_dataList addObject:book];      

 }

然后实现UItableViewDataSource代理方式

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _dataList.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = @"bookCell";
BookCell *bookCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (bookCell == nil)
{
bookCell = [[BookCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
NSBundle *bundle = [NSBundle mainBundle];
NSArray *array = [bundle loadNibNamed:@"BookCell" owner:nil options:nil];
bookCell = [array lastObject];
} Book *book = _dataList[indexPath.row];
bookCell.bookPrice.text = book.bookPrice;
bookCell.bookName.text = book.bookName; return bookCell; }

运行以后没有任何数据,也没有错误,跟踪调试后发现-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法没有执行,再继续跟踪,发现

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
2 {
3         return _dataList.count;
4 }

这个方法的返回值是0,即使 _dataList.count是0,为什么是0,原来在定义的时候把 _dataList 属性写成了weak,所以就没有retain,要写成strong。由于- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 的返回值是0,所以就不会调用-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 了。

关于weak和strong看这篇文章http://www.2cto.com/kf/201303/192824.html;

-tableView: cellForRowAtIndexPath:方法不执行问题的更多相关文章

  1. TableView数据源方法的执行顺序

    UITableView显示数据的过程 1.调用一次tableView:numberOfRowsInSection:方法确定行数 2.调用多次tableView:heightForRowAtIndexP ...

  2. 使用storyboard显示UITableView时,如果不修改系统默认生成的tableView:cellForRowAtIndexPath:方法中的代码,则必须为UITableViewCell注册(填写)重用标识符:identifier.必须要代码方法中的标识符一致.

    CHENYILONG Blog 使用storyboard显示UITableView时,如果不修改系统默认生成的tableView:cellForRowAtIndexPath:方法中的代码,则必须为UI ...

  3. cellForRowAtIndexPath方法不执行的那些坑

    今天用到了uitableview,是xib形式的.不过cellForRowAtIndexPath方法死活不执行,检查了返回的row数量,section的数量,数据源,代理都没问题,不过cellForR ...

  4. 【iOS】tableView:cellForRowAtIndexPath: 方法未调用

    今天遇到这个问题, UITableView 的代理方法 tableView:cellForRowAtIndexPath: - (UITableViewCell *)tableView:(UITable ...

  5. tableView:cellForRowAtIndexPath:方法中indexPath.row不是从0开始的,从4开始

    问题描述:重新刷新数据源,刷新列表时,发现前面4个cell没有显示出来,直接从第5条开始的,这是什么东东? 在tableView:numberOfRowsInSection:方法里打印数据源个数,是正 ...

  6. tableView创建方法调用的研究

    当两个section的cell数量都为5的时候,方法的调用顺序: -[ViewController numberOfSectionsInTableView:] -[ViewController tab ...

  7. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath不执行的问题

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPa ...

  8. tableView代理方法的调用时间,(主要是heightForRowAtIndexPath和cellForRowAtIndexPath调用时间)

    最近做一个demo,涉及按照数据分类然后依照分类在 cellForRowAtIndexPath形成不同类型的cell,就是有判断(在viewdidload里面做)和形成(在 cellForRowAtI ...

  9. tableView代理方法执行顺序

    tableView代理方法执行顺序,随着iOS系统版本的不断升级,执行顺序也有所变化 1.iOS7.1中先依次调一遍heightForRow方法再依次调一遍cellForRow方法,在调cellFor ...

随机推荐

  1. ural 1156. Two Rounds

    1156. Two Rounds Time limit: 2.0 secondMemory limit: 64 MB There are two rounds in the Urals Champio ...

  2. python 代码片段5

    #coding=utf-8 # python 有两个主要数据类型:int和float.根据Kiss原则,python只有一宗整数类型int. print 3**3 print int('123') p ...

  3. storm环境搭建(前言)—— 翻译 Setting Up a Development Environment

    Setting Up a Development Environment 搭建storm开发环境所需步骤: Download a Storm release , unpack it, and put ...

  4. HTMl5/CSS3/Javascript 学习推荐资源

    HTMl5/CSS3/Javascript 学习推荐资源 前端的定义应该是数据内容的展示,在国内大家都觉得前端只是HTML+CSS+Javascript,但是实际上与展示有关的都是前端,所以Ruby/ ...

  5. 【wikioi】1116 四色问题

    题目链接 算法:DFS 刚开始卡了一下,但后面想了想,于是 放上代码: #include <iostream> using namespace std; bool map[9][9]; i ...

  6. 【wikioi】1034 家园(最大流+特殊的技巧)

    http://wikioi.com/problem/1034/ 太神了这题. 其实一开始我以为是费用流,但是总感觉不对. 原因是我没看到一句话,特定的时刻到达特定的点!! 也就是说,并不是每艘船每次都 ...

  7. mysql中datetime比较大小问题 (转的)

    方法一: 你也可以:select * from t1 where unix_timestamp(time1) > unix_timestamp('2011-03-03 17:39:05') an ...

  8. asp.net 微信企业号办公系统-流程设计--流程步骤设置-按钮设置

    按钮设置是配置当前步骤的处理者可以执行哪些操作,每个按钮都有对应的执行脚本(javascript脚本). 从左边的按钮列表中选择当前步骤需要的按钮. 注意:如果是流程最后一步则要配置完成按钮而不是发送 ...

  9. linux系统tomcat启动正常访问不到主页面

    环境: linux系统 tomcat 6.0.24 jdk 1.6 防火墙的问题: 查看防火墙命令:chkconfig --list | grep -i iptables 关闭防火墙命令:/sbin/ ...

  10. 【C语言】04-函数

    一.函数的分类 前面已经说过,C语言中的函数就是面向对象中的"方法",C语言的函数可以大概分为3类: 1.主函数,也就是main函数.每个程序中只能有一个.也必须有一个主函数.无论 ...