关于UINavigationController与UITableView聚合的发现
来源:互联网 发布:数据库应用软件开发 编辑:程序博客网 时间:2024/05/18 06:39
今天写iOS项目时,发现了几个问题,于是停下项目,好好地进行了一番研究(已发现文中问题的亲们可跳过,哈哈):
当我们的视图(控制器的视图)中有导航条,即导航控制器自动为我们添加的导航条时。
通过导航控制器来控制视图:
self.window.rootViewController=[[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
我们在控制器的视图中添加子视图时,子视图显示内容的y坐标是相对于视图的最顶端来说的。如图:
添加视图的代码如下:
- (void)viewDidLoad { [super viewDidLoad]; CGFloat width=self.view.frame.size.width; self.view.backgroundColor=[UIColor whiteColor]; UIView* view1=[[UIView alloc] init]; view1.frame=CGRectMake(0, 0, width, 64); [self.view addSubview:view1]; view1.backgroundColor=[UIColor redColor]; UIView* view2=[[UIView alloc] init]; view2.frame=CGRectMake(0, 64, width, 64); [self.view addSubview:view2]; view2.backgroundColor=[UIColor yellowColor];}
上面的显示是显而易见的。
但是当我们添加UITableView
时问题就来了。
在视图中手动添加UITableView
:
在添加UITableView
之前,如果在控制器的视图中添加了另外一个子视图的话,那么UITableView
的显示内容(包括tableHeaderView、tableFooterView和UITableViewCell)是以控制器的顶端为y的坐标起点的。
- (void)viewDidLoad { [super viewDidLoad]; CGFloat width=self.view.frame.size.width; CGFloat height=self.view.frame.size.height; self.view.backgroundColor=[UIColor whiteColor]; UIView* view1=[[UIView alloc] init]; view1.frame=CGRectMake(0, 0, width, 100); [self.view addSubview:view1]; view1.backgroundColor=[UIColor greenColor]; self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 64, width, height) style:UITableViewStylePlain]; self.tableView.dataSource=self; [self.view addSubview:self.tableView]; self.tableView.backgroundColor=[UIColor redColor];}
显示效果如图:
但是,如果在添加UITableView
之前并没有在控制器的视图中添加别的子视图,则UITableView
的显示内容是以导航栏的底部为y的坐标起点的。
- (void)viewDidLoad { [super viewDidLoad]; CGFloat width=self.view.frame.size.width; CGFloat height=self.view.frame.size.height; self.view.backgroundColor=[UIColor whiteColor]; self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, width, height) style:UITableViewStylePlain]; self.tableView.dataSource=self; [self.view addSubview:self.tableView]; self.tableView.backgroundColor=[UIColor redColor]; UIView* view1=[[UIView alloc] init]; view1.frame=CGRectMake(0, 0, width, 100); [self.view addSubview:view1]; view1.backgroundColor=[UIColor greenColor];}
注意:不管怎么设置,只是UITableView
的显示内容的y坐标发生了改变,UITableView
自身还是如平常那样。
0 0
- 关于UINavigationController与UITableView聚合的发现
- UINavigationController,UITableview的使用
- IOS之7版本适配UITableVIew与UINavigationController
- 关于Docker的服务发现与注册
- iOS UItableView+UINavigationController实现单元格的删除
- iOS UItableView+UINavigationController实现单元格的删除
- UINavigationController与UITabbarController的样式
- COM原理与应用中关于聚合实现的纪要
- 关于UINavigationController
- 关于UITableView的优化
- 关于UITABLEVIEW的使用说明
- 关于UITableView的优化
- 关于UITableView的优化
- 关于UITableView的优化
- 关于 UITableView 的优化
- UITableView 关于cell与cell之间的间距
- 关于组合与聚合与继承
- 关于聚合的几个例子
- 【CTSC1999】补丁vs错误 状压最短路
- 黑马程序员——面试题小总结1
- Cocos2D物理碰撞不按预期工作的排查工作
- 黑马程序员——面试题小总结2
- 单点登录
- 关于UINavigationController与UITableView聚合的发现
- ARM assembler in Raspberry Pi – Chapter 3
- Andorid多线程断点续传下载
- 【软/自考】算法实用技巧——递归VS迭代
- while判断值为cin输入值时,注意调试时要用文件结束符结束循环
- PHP:Fatal error: Class 'COM' not found in … 的处理办法
- free(): invalid pointer
- Linux抓包
- C++之文件重定向 通过txt读入数据和txt写数据