ios tableviewcontroller
方法
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier" forIndexPath:indexPath];
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier"];
之间的区别
下面是stack 里找到的答案
The most important difference is that the forIndexPath:
version asserts (crashes) if you didn‘t register a class or nib for the identifier. The older (non-forIndexPath:
) version returns nil
in that case.
You register a class for an identifier by sending registerClass:forCellReuseIdentifier:
to the table view. You register a nib for an identifier by sending registerNib:forCellReuseIdentifier:
to the table view.
If you create your table view and your cell prototypes in a storyboard, the storyboard loader takes care of registering the cell prototypes that you defined in the storyboard.
如果没有注册一个class 或者 一个nib , 使用 前者( forindexpath ) 会报错。
附上stackoverflow 链接 http://stackoverflow.com/questions/25826383/when-to-use-dequeuereusablecellwithidentifier-vs-dequeuereusablecellwithidentifi
http://stackoverflow.com/questions/12737860/assertion-failure-in-dequeuereusablecellwithidentifierforindexpath
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。