IOS Tableview的两种系统样式
来源:互联网 发布:淘宝创业培训班 编辑:程序博客网 时间:2024/09/21 11:21
默认情况下,如果不带xib。tableview样式是plain样式,不自动产生组头和组尾。如下图,创建一个不带xib的Controller
看这段代码:
- (void)viewDidLoad { [super viewDidLoad]; //没有xib的tableviewController 默认为plain样式,分section也不会有组头,组尾。如果加上下面代码,就会有组头组尾// self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStyleGrouped]; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}#pragma mark - Table view data source- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 5;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //两个参数的方法 表示 从cell空闲队列中去名字叫@“cell”的单元格,如果没有取到,tableView会根据我们之前注册样式,帮我们创建一个cell使用,如果取到,就使用取出来的 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; cell.textLabel.text = @"这是一个单元格"; return cell;}
实现效果如下: 两个section 也没有分组效果
下面我们看,如果打开注释代码,强写为分组样式:
- (void)viewDidLoad { [super viewDidLoad]; //没有xib的tableviewController 默认为plain样式,分section也不会有组头,组尾。如果加上下面代码,就会有组头组尾 self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStyleGrouped]; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];}
效果如下:
自动产生分组头,和分组脚。好了,这就是tableview的两种系统样式
阅读全文
0 0
- IOS Tableview的两种系统样式
- 常用两种系统体系结构的比较
- 两种系统间通信方式的比较
- 两种系统启动&加载QT库
- iOS 两种系统分享(配Demo下载)UIActivityViewController 和 SLComposeViewController
- ios tableview一些样式的整理
- Linux与WinCE驱动开发对比之一 —— 两种系统的发展趋势
- Linux与WinCE驱动开发对比之一 —— 两种系统的发展趋势
- 两种系统热备方案
- 十四种系统故障的解决方法
- 十四种系统故障的解决方法
- Ceph管理系统的几种系统
- 获取几种系统服务的方法
- iOS-修改TableView分割线样式
- iOS tableView 设置选中type样式
- 几种系统总线
- 几种系统调用
- SQL Serve 2000 的四种系统数据库
- HDU-5835 一道特别简单的题
- 48. Rotate Image
- QT Qtablewidget表头设置(从Qstring中提取表头)
- 数据结构实验之栈三:后缀式求值
- Runnable匿名内部类实现线程
- IOS Tableview的两种系统样式
- AppCompatActivity和Activity的setContentView方法的区别
- Hadoop c++开发
- 初学Android之飞机大战(四)——Boss
- 蓝桥决赛---分机号
- name 'raw_input' is not defined(Python 报错)
- 计算字符个数等
- 使用docker容器定制镜像(image)并部署简单 web应用
- 详解MySQL的用户密码过期功能