这让我疯了!
我有一个通用的UITableViewController类,带有一个通用的原型单元格,标识符为“myCell”.在ARC,iOS5下开发并使用Storyboard,我使用以下方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"]; cell.textLabel.text = @"Title"; return cell; }
一切都挂在故事板,文件所有者等等.我的项目中有几个其他UITableViewController,使用相同的概念.一切正常.
这个特殊类的UITableViewController不想工作!继续向我抛出异常:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
Nslog’ed – > [tableView dequeueReusableCellWithIdentifier:@“myCell”] =(null)
非常感谢任何想法和帮助!
编辑:
为简单起见:
– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
返回1;
}
我已经完成的事情:
1.在故事板中删除并创建和设置UITableViewController!
2.重新启动Xcode
3.重新启动模拟器
4.重启电脑!!!!
5.一遍又一遍地删除并构建应用程序!
没有用.
顺便说一下,我试过了
if (cell == nil) cell = [UITableViewCell alloc] initWithStyle....
..它将解决问题,但是再次……这是ARC,故事板,……我不应该这样做. Xcode应该照顾它!
解决方法
你必须创建你的单元格:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"myCell"] autorelease]; } cell.textLabel.text = @"Title"; return cell; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。