为什么是"tableview.cellForRowAtIndexPath(indexPath)"?给我一个BAD_ACCESS错误? [英] Why "tableview.cellForRowAtIndexPath(indexPath)" give me a BAD_ACCESS error?

查看:189
本文介绍了为什么是"tableview.cellForRowAtIndexPath(indexPath)"?给我一个BAD_ACCESS错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用此方法来获取该indexPath的单元格,但出现了此"EXC_BAD_ACCESS"错误. 但是,如果我使用self.tableView(tableView, cellForRowAtIndexPath:indexPath),它可以正常工作.

I attempted to use this method to get the cell of that indexPath, but I got this "EXC_BAD_ACCESS" error. But if I use self.tableView(tableView, cellForRowAtIndexPath:indexPath), it works fine.

我很困惑这两种方法有什么区别?

I am confused what's the difference between that two methods?

推荐答案

使用self.tableView(tableView, cellForRowAtIndexPath:indexPath)是您的View Controller的代码,并且出队是一个合适的新单元格.而如果单元格不可见,则表视图上的cellForRowAtIndexPath方法将返回nil.由于heightForRowAtIndexPath试图找出可见的行,因此不起作用并不奇怪.

Using self.tableView(tableView, cellForRowAtIndexPath:indexPath) is the code is your View Controller, and it dequeue's a suitable new cell. Whereas, the cellForRowAtIndexPath method on the table view returns nil if the cell is not visible. Since heightForRowAtIndexPath is trying to work out which rows are visible, it's not surprising that it doesn't work.

> SO答案表明在heightForRowAtIndexPath中调用cellForRowAtIndexPath递归调用自己.这就是为什么您会收到错误消息.

This SO answer shows that calling cellForRowAtIndexPath within heightForRowAtIndexPath recursively calls itself. Which is why you're getting the error.

这篇关于为什么是"tableview.cellForRowAtIndexPath(indexPath)"?给我一个BAD_ACCESS错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆