iOS开发之UITableView详解
来源:互联网 发布:福建网络继续教育学院 编辑:程序博客网 时间:2024/05/17 04:13
表示图可谓是iOS开发中最常用的一个控件,没有之一。深入学习之后你会发现他有很多强大的功能,几乎可以用tableView实现所有的UI界面。
//表示图的创建 self.tableView=[[UITableViewalloc]initWithFrame:self.view.frame style:UITableViewStylePlain]; //设置代理 self.tableView.delegate =self; self.tableView.dataSource =self; //设置背景颜色 self.tableView.backgroundColor = [UIColorredColor]; //分割线样式 self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; //分割线颜色 self.tableView.separatorColor = [UIColorblueColor]; //行高 self.tableView.rowHeight =80;
//表示图的一些常用代理方法和数据源方法#pragma mark ---------- UITableViewDelegate- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"点击方法!!!");}
//返回每一行cell的高度,要比设置rowHeight更灵活- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section ==0) { return 66; } else if (indexPath.section ==1) { return 88; } return 44;}
//头部分区高度- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 50;}
//尾部分区高度- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 30;}
//自定义分区头部- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UIView *headView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,self.frame.size.width,44)]; headView.backgroundColor = [UIColorgreenColor]; return headView;}
//自定义分区尾部- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ UIView *footView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,self.frame.size.width,44)]; footView.backgroundColor = [UIColoryellowColor]; return footView;}
#pragma mark -- UITableViewDataSource
//返回分区有多少行- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 10;}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifier =@"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier]; } //INSERT CODE cell.textLabel.text =@"iOS开发"; return cell;}
#pragma mark -- 选择实现的代理方法
//显示有几个分区- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 3;}
//分区头部标题- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ if (section == 0) { return @"第一段标题"; } else if (section ==1) { return @"第二段标题"; } return@"段头标题";}
//分区尾部标题- (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{ if (section == 0) { return @"第一段段尾"; } else if (section ==1) { return@"第二段段尾"; } return@"段尾标题";}
//右侧索引内容- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ NSArray *array = @[@"k",@"z",@"s"]; return array;}
1 0
- iOS开发之UITableView详解
- 芒果iOS开发之UITableView详解
- 【IOS开发】UITableView详解
- IOS控件之UITableView详解
- iOS 之 UITableView 使用详解
- iOS开发 UITableView之cell
- iOS开发学习之UITableView
- 4、iOS 开发之 UITableView
- ios开发系列之UITableView
- iOS开发之UITableView多选
- iOS开发之自定义UITableView
- iOS开发-UITableView多层详解-UITableview多层级开发
- iOS开发 - 最常用控件 UITableView详解
- iOS UITableView索引列开发详解
- iOS开发 - 最常用控件 UITableView详解
- iOS开发 ☞ UITableView详解(一)
- iOS开发 ☞ UITableView详解(二)
- iOS学习之——UITableView详解
- 图片上传之前预览
- Swift 数组
- 摆脱臃肿--Unity3D安卓包减肥秘笈
- c++字符串处理函数
- Leetcode #258 Add Digits
- iOS开发之UITableView详解
- 行人检测相关资源
- 以日期时间加四位随机数作序列
- C-011.while和do...while 循环语句
- Debian8环境搭建freeswitch 1.7测试视频混屏效果
- Android SDK开发范例大全 ---3.4置换TextView文字
- AES —— JAVA中对称加密和解密
- Oracle中job的使用
- 编程的智慧