关于UINavigationController与UITableView聚合的发现
2015-10-13 07:54
645 查看
今天写iOS项目时,发现了几个问题,于是停下项目,好好地进行了一番研究(已发现文中问题的亲们可跳过,哈哈):
当我们的视图(控制器的视图)中有导航条,即导航控制器自动为我们添加的导航条时。
通过导航控制器来控制视图:
我们在控制器的视图中添加子视图时,子视图显示内容的y坐标是相对于视图的最顶端来说的。如图:
添加视图的代码如下:
上面的显示是显而易见的。
但是当我们添加
在视图中手动添加
在添加
显示效果如图:
但是,如果在添加
注意:不管怎么设置,只是
当我们的视图(控制器的视图)中有导航条,即导航控制器自动为我们添加的导航条时。
通过导航控制器来控制视图:
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自身还是如平常那样。
相关文章推荐
- SpriteBuilder中不能编辑自定义类或不能给节点添加属性的解决
- SpriteBuilder中不能编辑自定义类或不能给节点添加属性的解决
- SpriteBuilder中不能编辑自定义类或不能给节点添加属性的解决
- UIScrollView-----1基本使用
- UIButton 按钮控件-IOS开发
- AmazeUI定制
- 3.uedit富文本编辑器的使用_note
- solrcloud随笔DistributedQueue
- android高分段进阶攻略(3)旋转等待UI界面设计
- iOS UITableView下拉刷新上拉加载更多MJRefresh类库(推荐)使用初级剑侠篇(欢迎提建议和分享遇到的问题)
- iOS编程------UIAlertController
- 开源中国源码学习UI篇(三)之ViewPager+Fragment的使用分析
- 【IOS 开发学习总结-OC-44】★★ios开发之UI控件——文本框与多行文本控件(彩蛋——上拉刷新一般实现代码)
- iOS的UINavigationController简单使用入门(状态:已完成)
- 最长公共子序列(Longest Common Subsequence,LCS)
- Android UI 设计:ListView控件和ArrayAdapter适配器(二)
- Android UI设计:ListView 控件与 Adapter 适配器
- 理解UIEdgeInsets
- leetcode之Implement Stack using Queues
- (key,value)对value进行排序