cell的3三种重用方法
来源:互联网 发布:手机淘宝用银行卡支付 编辑:程序博客网 时间:2024/05/16 12:11
cell的重用
重用标识符可以定义为全局的
static NSString *const reuseIdentify = @“Cell”;
1.一个类(含.h,.m)
例如
RightDetailCell.h文件
RightDetailCell.m文件
//重写父类的初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [superinitWithStyle:UITableViewCellStyleValue1reuseIdentifier:reuseIdentifier];
if (self) {
self.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
}
returnself;
}
在ViewController.m 的生命周期注册重用标识符(ViewDidLoad里或其他懒加载位置)
#import "RightDetailCell.h"
[self.tableView registerClass:[RightDetailCell class] forCellReuseIdentifier:@"RDCell"];
再在cellForRowAtIndexPath或者cellForItemAtIndexPath里从队列取出重用
RightDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RDCell" forIndexPath:indexPath];
2.一个带xib的类(含.h .m .xib)
NormalCell.h文件
@interface NormalCell : UITableViewCell
@property (weak,nonatomic)IBOutletUIImageView *iconIV;
@property (weak,nonatomic)IBOutletUILabel *titleLb;
@property (weak,nonatomic)IBOutletUILabel *detailLb;
NormalCell.m文件
NormalCell.xib文件
1).在xib里画出需要使用的参数(view imageView label等) 并写出cell的标志符
2).将xib的cell里面的参数连接到.h的属性中(公开的)
3).在指定controller里面根据xib注册重用标识符
#import "NormalCell.h"
[self.tableView registerNib:[UINib nibWithNibName:@"NormalCell" bundle:nil] forCellReuseIdentifier:@"normalCell"];
4)再在cellForRowAtIndexPath或者cellForItemAtIndexPath里从队列取出重用
NormalCell *cell = [tableView dequeueReusableCellWithIdentifier:@"normalCell" forIndexPath:indexPath];
3.纯xib
DaRenCell.xib文件
重用标识符DaRenCell写上
if (indexPath.row ==2) {
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"DaRenCell"];
if (cell ==nil) {
cell = [[NSBundlemainBundle]loadNibNamed:@"DaRenCell"owner:niloptions:nil].firstObject;
}
return cell;
}
//1.有多少个分组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return4;
}
//2.某个分组中有几个cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [@[@3,@2,@3,@1][section]integerValue];
}
//3.cell样式
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- cell的3三种重用方法
- UITableView的两种重用Cell方法的区别
- 使用重用机制创建cell的两种方法
- tableview的两个重用cell方法
- tableview的两个重用cell方法 (转)
- tableview的两个重用cell方法
- UITableViewCell注册Cell并重用的方法
- UITableView cell的重用
- Cell的重用代码
- Cell的重用原理
- Cell的重用机制
- Cell的重用原理
- cell的重用机制
- 关于cell的重用
- cell的重用机制
- Cell的重用代码
- cell的重用机制
- cell的重用问题
- JSTL(自定义标签)
- MVVM架构
- Java 发送邮件
- Kali 解决默认启动HDMI没有声音问题
- 13.1节练习
- cell的3三种重用方法
- 让我震惊的SqlServer 对 ''特殊的处理
- Android 常用知识总结
- 指针小结
- Java中的堆和栈
- ViewPager简单用法
- “车城”项目问题总结之UITableView不同样式cell的运用
- Java 网络编程
- Android 字符串截取替换函数