tableView大家都用的非常之多,一千一直使用代码创建所有的页面控制器  ,最近一直在学习熟悉使用storyboard ,于是又开始走上了手动拖动空间的方法来构造页面。今天遇到一个问题 ,为何我手动创建的cell上面的元素 显示不了,但是cell里面的方法可以执行。 断点调试 ,发现cell.nameLabel的打印结果为null,而且在 cell的构造函数中,没有执行 以下一段 

TestCustomCell *cell = (TestCustomCell*)[tableView dequeueReusableCellWithIdentifier:TestStringCellNameCellIdentifier forIndexPath:indexPath];
    if (cell==nil) {
        cell = [[TestCustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TestStringCellNameCellIdentifier];
        
    }
    
    
    [cell setCustomCell:@"is 1" twoLabel:@"is 2" thebutton:@"is 3"];

    return cell;

注意,是if条件的语句没有执行 ,为何呢 ,第一次执行  cell应该是nil才对 ,为何没有执行呢?这就是问题所在,

最后找出来 是因为在viewdidLoad里面 使用了regster注册了cell 因此cell已经被提早构建 ,不会再执行里面的函数了,但是cell仍然为空,要正确展示cell里里面的元素  ,自定义的cell是不能注册的 ,(除非你是代码创建),问题解决啦

posted on 2014-05-09 17:27  无涯之径  阅读(133)  评论(0编辑  收藏  举报