tableviewcell注册和不注册的区别及用法

2019-04-29  本文已影响0人  13d8cd576232

注册和不注册的区别主要看下面这两个方法:

- (nullable __kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier; 
 // Used by the delegate to acquire an already allocated cell, in lieu of allocating a new one.
(返回给代理一个已经分配的cell,代替一个新的cell,如果没有已分配的cell,则返回nil,使用这个方法就不需要注册了)

- (__kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0); 
// newer dequeue method guarantees a cell is returned and resized properly, assuming identifier is registered  
如果cell的identifier是注册过的,那么这个新列出的方法保证返回一个cell (有分配的就返回已分配的cell,没有返回新的cell)并适当调整大小,可省略cell空值判断步骤,用这个方法cell必须注册,不是自定义的cell,UITableViewCell也要注册

个人博客地址:https://youyou0909.github.io

上一篇下一篇

猜你喜欢

热点阅读