ios dequeueReusableCellWithIdent

作者: 老夫撩发少年狂 | 来源:发表于2017-01-12 09:49 被阅读178次

tableview中有两种创建cell的方法 ,在这里记录一下顺便复习

1.第一种方法:dequeueReusableCellWithIdentifier: forIndex

新方法

此方法是IOS6.0+版本才出现的,新的重用机制方法;只能在IOS 6.0以上系统才有效;注意官方SDK说明:newer dequeue method guarantees a cell is returned and resized properly, assuming identifier is registered

即:使用dequeueReusableCellWithIdentifier: forIndex: 必须使用配套的

- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier

或者

- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier这个方法。对每一个tableview的cell进行注册。

[self.tableview registerClass[UITableViewCellclass]forCellReuseIdentifier:@"IPHONE_LIST_CELL"];//进行注册。

2.第二种方法:使用 dequeueReusableCellWithIdentifier:时,后面的cell要判断为空时,生成一个cell,

注明:使用1的新方式重用机制,如果没有对tableviewregisterClass注册cell的话,会闪退报错:

must register a nib or a class for the identifier or connect a prototype cell in a storyboard’

相关文章

网友评论

    本文标题:ios dequeueReusableCellWithIdent

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