今天在学习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. BZOJ2674 : Attack

    整体二分+树状数组套Treap,时间复杂度$O(n\log^3n)$. #include<cstdio> #include<cstdlib> #include<algor ...

  2. HDU 1180 (BFS搜索)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1180 题目大意:迷宫中有一堆楼梯,楼梯横竖变化.这些楼梯在奇数时间会变成相反状态,通过楼梯会顺便到达 ...

  3. 生产环境下一定要开启mysqlbinlog

    在没有备份数据库的情况下,可以用binlog进行恢复 在生产环境下安全第一,损失一点点效率换来的安全还是值得的. http://www.cnblogs.com/zc22/archive/2013/06 ...

  4. 【wikioi】1012 最大公约数和最小公倍数问题

    题目链接 算法:辗转相除(欧几里得) gcd(a, b)是a和b最小公倍数, lcm(a, b)是a和b的最大公倍数 gcd(a, b) == gcd(b, a%b) 时间复杂度: O(lgb) 具体 ...

  5. NOIP200304麦森数

    试题描述 形如2P-1的素数称为麦森数,这时P一定也是个素数.但反过来不一定,即如果P是个素数,2P-1不一定也是素数.到1998年底,人们已找到了37个麦森数.最大的一个是P=3021377,它有9 ...

  6. mysql中datetime与timestamp的比较

    相同 显示 TIMESTAMP列的显示格式与DATETIME列相同.换句话说,显示宽度固定在19字符,并且格式为YYYY-MM-DD HH:MM:SS. 不同 范围 datetime 以'YYYY-M ...

  7. Java_BigDecimal类型比较大小

    这个类是java里精确计算的类 1 比较对象是否相等 一般的对象用equals,但是BigDecimal比较特殊,举个例子: BigDecimal a=BigDecimal.valueOf(1.0); ...

  8. Update From 用法

    今天遇到用一个表的字段填充另一个表的问题,整理了一下   1.在mysql中,应该使用inner join,即: UPDATE   a INNER JOIN b ON a.userName = b.u ...

  9. sftp配置

    sftp不需要安装,只需要借助sshd服务器即可使用. 增加用户useradd -s /bin/false mysftp 设置用户密码passwd mysftp 创建用户家目录mkdir /home/ ...

  10. kvm快照

    Kvm快照: 1.基于lvm的快照 2.kvm自带的快照功能(需要qcow2 磁盘文件才支持快照) 关闭kvm虚拟机: 查看磁盘文件信息: [root@super67 ~]# qemu-img inf ...