今天在学习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. !cocos2d 重复添加action事件

    当点击的时候,如果不是按照开始点击计算的,那么持续点击会导致不会变大. void Piece::setActived(bool active) { _actived = active; CCActio ...

  2. oracle系列--第三篇 Oracle的安装

    在安装之前,我先说说我的电脑的配置: OS : Windows 7 32bit CPU : 3GHz Memory : 2GB Desk : 320GB ======================= ...

  3. android ScrollView滚动距离和判断滚动停止状态

    今天很高兴,自己解决了判断ScrollView滚动停止的监听,现在分享给大家. 因为ScrollView没有像listView中的setOnScrollListener()监听,当然也就没有SCROL ...

  4. 【回文串-Manacher】

    Manacher算法能够在O(N)的时间复杂度内得到一个字符串以任意位置为中心的回文子串.其算法的基本原理就是利用已知回文串的左半部分来推导右半部分. 转:http://blog.sina.com.c ...

  5. NSCharacterSet 简单用法

    NSCharacterSet 简单用法 NSCharacterSet其实是许多字符或者数字或者符号的组合,在网络处理的时候会用到 NSMutableCharacterSet *base = [NSMu ...

  6. WinEdt选项卡配置

    不小心把选项卡(标签页.多tab)整没了.搜了一下: 在工具栏点击右键可以发现配置.

  7. PAT (Top Level) Practise 1008 Airline Routes(Tarjan模版题)

    1008. Airline Routes (35) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Given a ...

  8. ubuntu下用virtualbox安装windows虚拟机

    按照这个教程: http://jingyan.baidu.com/article/eae07827856ac21fed54856f.html 安装. 会出现问题:"VT-x is disab ...

  9. 分布式文件系统FastDFS原理介绍

    在生产中我们一般希望文件系统能帮我们解决以下问题,如:1.超大数据存储:2.数据高可用(冗余备份):3.读/写高性能:4.海量数据计算.最好还得支持多平台多语言,支持高并发. 由于单台服务器无法满足以 ...

  10. 【翻译】Kinect Studio是? 三月 SDK Update的新机能

      Kinect应用软件开发支援工具「Kinect Studio」的功能和用法的说明.由于可以记录/再生数据,让开发和调试变得更加简单.   Kinect SDK v2预览版的RTM版的预定在发布之前 ...