UITableViewController的使用
2024-09-27 00:52:46
如果整个程序界面都只是使用UITableView来搭建,一般需要如下步骤:
(1)向界面上拖一个UITableView
(2)设置数据源
(3)设置代理
(4)遵守代理协议
上述过程相对繁琐,为了简化操作,直接使用UITableViewController,但要一定要注意:需要和主控制器类进行关联,还有就是不要把UIViewController当成UITableViewController使用。
自定义TableViewCell(在ATDemoCell.m里):
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
static NSString *ID = @"cellID";
ATDemoCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
cell = [[ATDemoCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:ID];
}
return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// 在此处定义控件
}
return self;
}
在cellForRowAtIndexPath数据源里调用
ATDemoCell *cell = [ATDemoCell cellWithTableView:tableView];
分割线设置
//设置分割线
[tableView setSeparatorInset:UIEdgeInsetsMake(0, -67, 0, 0)];
//分割线颜色
self.tableView.separatorColor = [UIColor redColor]; //隐藏分割线
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//隐藏多余分割线
self.tableView.tableFooterView = [[UIView alloc] init];
取消选中样式
//取消选中样式
cell.selectionStyle = UITableViewCellSeparatorStyleNone;
设置背景色
// 改变整个tableView的颜色
tableView.backgroundColor = [UIColor greenColor] // 设置选中的背景色
UIView *selectedBackgroundView = [[UIView alloc] init];
selectedBackgroundView.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = selectedBackgroundView; // 设置默认的背景色 1
cell.backgroundColor = [UIColor blueColor]; // 设置默认的背景色 2
UIView *backgroundView = [[UIView alloc] init];
backgroundView.backgroundColor = [UIColor greenColor];
cell.backgroundView = backgroundView;
右边指示器显示,比如箭头、打勾,也可以自定义图片等等
// 显示箭头
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// 自定义显示,如开关Switch
cell.accessoryView = [[UISwitch alloc] init];
设置tableview 不能滚动
self.tableView.scrollEnabled =NO;
最新文章
- DBobjectsCompareScript(数据库对象比较).sql
- C# 一段绘图代码 在form_load事件不能显示图
- MySQL复制配置(多主一从)
- qt播放器
- 相对路径获取项目文件 及报错 No mapping found for HTTP request with URI XXX in DispatcherServlet with name ‘springmvc’解决方法
- H5案例学习笔记
- HTML元素,属性,基础标签
- 用vs2008打开vs2012项目
- My97DatePicker的calendar.js的反混淆
- Squid代理服务器&;&;搭建透明代理网关服务器
- <;转>;maven发布第三方jar的一些问题
- sparse autoencoder
- hdu 4614 Vases and Flowers (二分 线段树)
- .net 实战 根据configuration选项生成不同的config文件
- JAVA之JDBC的简单使用(Mysql)
- SQL两表之间:根据一个表的字段更新另一个表的字段
- E. Bear and Drawing
- Android四大组件总结
- python常用模块之subprocess
- java中正则表达式基本用法(转)
热门文章
- vue.js学习之 打包为生产环境后,页面为白色
- /etc/fstab 文件如何填写(转)
- 关于智能指针类型shared_ptr的计数问题
- Line belt(三分镶嵌)
- 软件功能说明书——Thunder团队
- xml解析----java中4中xml解析方法(转载)
- OSG学习:移动/缩放/旋转模型
- ios::sync_with_stdio(false)提高C++读写速度
- 检测固定IP的端口是否开放批出
- MAC锁屏不断网(快捷键启用屏保)