iOS-UITableViewCell 没有被重用问题

2017-05-12  本文已影响0人  程程程程程子

昨天搬砖 发现了一个很奇怪的问题 我的自定义Cell 居然每次需要展示时都是重新创建的 

手写代码方式:两个步骤

1.注册cell identifier

[self.tableViewregisterClass:[SGAudioHistoryCellclass]forCellReuseIdentifier:[SGAudioHistoryCellcellIdentifier]];

2.在tableView cellForRowAtIndexPath 方法里

SGAudioHistoryCell* cell = [tableViewdequeueReusableCellWithIdentifier:[SGAudioHistoryCellcellIdentifier]forIndexPath:indexPath];

But 为什么不行能 在网上找原因 大家都是提供如何主动让cell不重用 囧了。后来发现我是在tableView添加到self.view之前 注册的cell identifier,我把位置换过来 果然好使了。

so,如果遇到这个问题 确认下

在注册cell identifier之前 tableView要已经添加到了父视图里 不要问我为什么 有知道的 可以回答下 多谢

上一篇 下一篇

猜你喜欢

热点阅读