UITableView 自定义UITableViewCell

本文不详解如何使用UITableView,只记录今天在开发过程中遇到的几个疑惑点。

- (nullable __kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier;

- (__kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);方法有什么不同。

首先,先看一下官方的解释

Used by the delegate to acquire an already allocated cell, in lieu of allocating a new one.

这是对前一种方法的解释,虽然英文不太好,勉强还是能看到几个关键点的,它是用来获得一个已经存在的cell,而不是去创建一个新的。

newer dequeue method guarantees a cell is returned and resized properly, assuming identifier is registered

这是对后一种的方法的解释,注意最后assuming identifier is registered,这就是说cell是从已经被注册的Class和Nib中来得。

- (void)registerNib:(nullable UINib *)nib forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(5_0);
- (void)registerClass:(nullable Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
这两个方法用来注册自定义的cell。
也就是说要想使用- (__kindof UITableViewCell *)dequeueReusableCellWithIdentifier: forIndexPath:来获得cell,你得确保你的UITableView以及有注册好的cell,否则或造成crash。

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

推荐阅读更多精彩内容

友情链接更多精彩内容