懒加载的时候注册 Cell :
- (UITableView *)homeTableView{ if (!_homeTableView) { _homeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) style:UITableViewStylePlain]; self.homeTableView.delegate = self; self.homeTableView.dataSource = self; [self.homeTableView registerClass:[HomeTableViewCell class] forCellReuseIdentifier:_identifier]; [self addSubview:self.homeTableView]; } return _homeTableView; }
然后创建 Cell 的时候报错 :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ HomeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:_identifier forIndexPath:indexPath]; NSLog(@"%@",cell); NSDictionary * dic = _nowNewsDataArr[indexPath.row]; [cell config:dic]; return cell; }
我实在没办法了,搜了好久没搜到
![]() | 1 banxi1988 2016-11-01 13:16:57 +08:00 一眼看不出错误,最后搞一个 Demo 方便别人帮助你. |
![]() | 3 lisonfan OP |
![]() | 4 f19009 2016-11-01 14:06:18 +08:00 用 [tableView dequeueReusableCellWithIdentifier:@"identifier"] 这个方法 |
![]() | 5 lisonfan OP @f19009 用 - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0); 无限递归,这是为毛。。 |
![]() | 6 acumen 2016-11-01 14:33:54 +08:00 via iPhone 弱问:懒加载里 self.homeTableView 不会无限递归吗? |
![]() | 7 CommandZi 2016-11-01 15:06:52 +08:00 你把懒加载里面的 self.homeTableView 都改成 _homeTableView |
![]() | 9 SeanChense 2016-11-01 15:27:53 +08:00 刚翻 Stack overflow 就看到楼主的问题 |
![]() | 10 SeanChense 2016-11-01 15:32:25 +08:00 楼主在 heightForRowAtIndexPath 里调了 cellForRowAtIndexPath ,然鹅后者又要调前者 |
![]() | 11 lisonfan OP @SeanChense 英语渣的一逼就删了 |
![]() | 12 lisonfan OP |
![]() | 13 SeanChense 2016-11-01 15:37:15 +08:00 @lisonfan 这方面的教程很多,可以搜索下 |
![]() | 14 SeanChense 2016-11-01 15:41:41 +08:00 楼主的代码比较清奇 有几个槽点 1.mj 那个 block 是被 copy 起来的, self 会被持有循环引用 2.把 cell 绑定的数据换成 Model 吧, dict 太初级了 3.像 `- (void)initWithHomeTableView;` 这样的 initWithXXX 方法,第一楼主返回的 void 这很诡异,第二 WithXXXX 一般 XXX 是参数签名 其他没看了 |
![]() | 15 lisonfan OP @SeanChense 好的,非常感谢你的提点,不然不知道要被困扰多久 |
![]() | 16 cookiezby 2016-11-01 15:52:13 +08:00 提醒下楼主把 gitignore 设置好, Pod 文件夹下的东西一般是不用 commit 的。 |
![]() | 18 lisonfan OP |
![]() | 19 SeanChense 2016-11-01 17:05:39 +08:00 @lisonfan 没事,我也这样过来的。不断学习。 Pod 要不要加到 ignore 得看情况,像这样你要发出来给别人看就不能忽略,给别人造成困扰。 |
![]() | 20 lisonfan OP @SeanChense 嗯嗯,刚刚把配置改了 |
![]() | 21 iOran 2016-11-09 23:52:39 +08:00 最重要的错误是生成 homeTableView 的时候。本意是写一个 getter 方法来获取 homeTableView ,但你在 getter 方法里面调用 self. homeTableView ,这里有严重的 Bug 。 |