博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS开发UI篇—UITableview控件使用小结
阅读量:7027 次
发布时间:2019-06-28

本文共 1927 字,大约阅读时间需要 6 分钟。

hot3.png

一、UITableview的使用

UITableViewDataSource   @required

1.多少组数据:

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;

2.多少行数据

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;    

3.设置cell的每组每行

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

2、通过代码方式自定义cell

(1)新建⼀一个继承自UITableViewCell的类

(2)重写initWithStyle:reuseIdentifier:方法

MessageCell.h

#import 
@interface MessageCell : UITableViewCell@property (retain, nonatomic) UIImageView *headImageView;@end

MessageCell.m

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];    if (self) {        self.selectionStyle = UITableViewCellSelectionStyleNone;        self.backgroundColor =  [UIColor colorWithHex:0xefefef];                UIView *ticketKuang = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWith, cellHeight)];        [self.contentView addSubview:ticketKuang];        ticketKuang.backgroundColor = [UIColor whiteColor];                //选择按钮        selectBtn = [[UIButton alloc]initWithFrame:CGRectMake(-44, 5, 44, 44)];        [selectBtn setImage:[UIImage imageNamed:@"icon_list_selectBox_normal"] forState:UIControlStateNormal];        [selectBtn setImageEdgeInsets:UIEdgeInsetsMake(12, 12, 12, 12)]; //{top, left, bottom, right}        [ticketKuang addSubview:selectBtn];                return self;    }}
/****使用系统或者自定义cell*****///    static NSString *cellIdentify =@"cellIdentify";//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];//    if(cell == nil)//    {          UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];          cell.selectionStyle = UITableViewCellSelectionStyleNone;//    }

转载于:https://my.oschina.net/u/2326662/blog/545577

你可能感兴趣的文章
JavaWEB程序员电脑必备配置
查看>>
我的友情链接
查看>>
oracle性能调优总结
查看>>
relink all the executables of 11g
查看>>
冲突域和冲突域
查看>>
Sass学习笔记 -- 嵌套
查看>>
linux日志分析及管理
查看>>
netapp学习(二)---开启DNS功能
查看>>
创建MYSQL用户及授权用户权限
查看>>
TextView颜色等属性在string.xml定义
查看>>
docker迁移容器
查看>>
HBase 表数据 导入导出
查看>>
PropertyGrid无意的发现DisplayNameAttribute及应用
查看>>
我的友情链接
查看>>
Android之计算缓存大小并且清空缓存
查看>>
tomcat报内存溢出,解决方案
查看>>
DI序曲二十五 App-V与Remote App综合使用
查看>>
LVS+Keepalived相关参考资料
查看>>
IOS学习之UINavigationController详解与使用(三)ToolBar
查看>>
Linux 内存管理机制
查看>>