iOS开发之UITableViewCell走赋值方法但是没值

1.首先看cell上的控件是否为nil
2.cell上控件初始化方法不对
3.cell的初始化方法不对

如果直接崩溃,检查cell的reuseIdentifier
代码创建方法应该为

  • (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {}return self;}

代理方法里应该为

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"teacherCell";
    WBTeacherTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

      if (cell == nil) {
          cell = [[WBTeacherTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
      }
      cell.teacImage.image = [UIImage imageNamed:@"temp_yuan"];
      cell.teacLabel.text = @"张三老师 ";
      cell.backgroundColor = [UIColor yellowColor];
      return cell;
    

    }

xib或者storyboard的为:
view里:

  • (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    }

delegate

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.classifyTable) {
    WBClassifyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"classifyCell" forIndexPath:indexPath];
    return cell;
    }

上面几项都是我自己遇到的坑...其实都是自己坑自己...希望大家的代码细心一点不要犯和我同样的错误😄

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 12,998评论 3 38
  • UITableViewCell 父类是UIView UITableView的每一行都是一个UITableViewC...
    翻这个墙阅读 11,686评论 0 1
  • 前言 最近忙完项目比较闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助。博主非科班出身,一些...
    GitHubPorter阅读 5,359评论 9 5
  • UITableViewCell控件空间构造 cell的子控件是contentView,contentView的子控...
    CoderZXS阅读 4,149评论 0 1
  • 眼看自己来这个公司的第一个项目,也是公司的核心项目即将上线了,细数一番,已有半年之久,中间也做了一些小项目,忍不住...
    david_zhw阅读 12,767评论 9 22

友情链接更多精彩内容