cell重用的几种方式
1.使用xib重用
?//ios6 之后推薦大家使用的重用方式
? ? //動(dòng)態(tài)的使用self獲得當(dāng)前類(lèi)名,來(lái)作為唯一的標(biāo)示
? ? NSString * identifier = NSStringFromClass([self class]);
? ? UINib * nib = [UINib nibWithNibName:identifier bundle:nil];
?? ? ? ? //注冊(cè)
? ? [tableView registerNib:nib forCellReuseIdentifier:identifier];
?? ?
? ? //先在緩存池中去,如果緩存池沒(méi)有可重用的cell,那么根據(jù)前面注冊(cè)的nib創(chuàng)建一個(gè)cell對(duì)象給你返回回來(lái)
? ? GPSubjectCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
?? ?
? ? return cell;
?
2,純代碼
?
?
? ? //保證標(biāo)示的唯一性,使用類(lèi)名是一種非常好的選擇
?? ?
? ? NSString * identifier = @"GPSubjectCell";
?? ?
? ? //1.先去緩存池中找是否有可以重用的
? ? GPSubjectCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
? ? //2.如果沒(méi)有可以重用的那么自己創(chuàng)建一個(gè)出來(lái)
? ? if(cell == nil)
? ? {
? ? ? ? cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
? ? }
?? ?
? ? return cell;
3.
//使用注冊(cè)的機(jī)制,實(shí)現(xiàn)純代碼cell類(lèi)的重用
? ? NSString * className = NSStringFromClass([self class]);
? ? [tableView registerClass:[self class] forCellReuseIdentifier:className];
? ? return [tableView dequeueReusableCellWithIdentifier:className];
?
4.使用storyboard 時(shí), (但必須給cell一個(gè)Identifier)
return? [collectionView dequeueReusableCellWithReuseIdentifier:@"bookCell" forIndexPath:indexPath];
轉(zhuǎn)載于:https://www.cnblogs.com/ouyangxiaoyao/p/5663393.html
總結(jié)
以上是生活随笔為你收集整理的cell重用的几种方式的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 建立集群间ssh信任关系
- 下一篇: C++ 类模板四(typename关键字