美文网首页
tableviewcell注册和不注册的区别及用法

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

作者: 13d8cd576232 | 来源:发表于2019-04-29 10:38 被阅读0次

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

    - (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

    相关文章

      网友评论

          本文标题:tableviewcell注册和不注册的区别及用法

          本文链接:https://www.haomeiwen.com/subject/hrlozftx.html