码迷,mamicode.com
首页 > 移动开发 > 详细

论UITableViewController被status bar覆盖的问题(IOS SDK 8.3)

时间:2015-06-17 21:47:38      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:uiviewcontroller   ios   

通常我们做一个UITableViewController(以下简称tvc)直接打开,在没有NavigationController的时候都会是这样
技术分享

问题是,你要加一个UINavigationController吗?

还是像别人一样不用UITableViewControler而是在main storyboard 里面造一个UIViewController + UITableView 下移20px?

告诉你我最近实现的一个方法:

#define BARITEMHEIGHT 64
- (void)viewDidLoad {
    [super viewDidLoad];
    CGRect frame = self.view.frame;
    frame.size.height = BARITEMHEIGHT;

    UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:frame];

    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"Active group"];
    UIBarButtonItem *leftbutton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(actionDown)];
    UIBarButtonItem *rightbutton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(actionCancel)];
    [navigationBar pushNavigationItem:navigationItem animated:YES];
    [navigationItem setLeftBarButtonItem:leftbutton];
    [navigationItem setRightBarButtonItem:rightbutton];
    self.tableView.tableHeaderView = navigationBar;

}


-(void) actionDown
{
    [self dismissViewControllerAnimated:YES completion:^{
        // balabalabala...
    }];
}

-(void) actionCancel
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

省事罗!
技术分享

  1. 由于加入的navigatebar是tableView的一部分,在手指滑动的时候这个navigatebar是会随着移动的,如果希望navigatebar不动,那么,就要把
- (void)viewDidLoad
{
...
}

里面的内容去掉
然后,在

-(void)viewDidAppear:(BOOL)animated
{
}

加上类似的内容,致于为什么加这里,可能是因为viewDidLoad的时候某些内部的控件还没有准备好吧

-(void)viewDidAppear:(BOOL)animated
{
    CGRect frame = self.view.frame;
    frame.origin.y += BARITEMHEIGHT;
    frame.size.height  -= BARITEMHEIGHT;
    self.view.frame = frame;

    frame.origin.y = 0;
    frame.size.height = BARITEMHEIGHT;

    UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:frame];

    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"Active appointment"];
    UIBarButtonItem *leftbutton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(actionDown)];
    UIBarButtonItem *rightbutton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(actionCancel)];
    [navigationBar pushNavigationItem:navigationItem animated:YES];
    [navigationItem setLeftBarButtonItem:leftbutton];
    [navigationItem setRightBarButtonItem:rightbutton];

    [self.view.superview addSubview:navigationBar];
}

感谢一下我吧!
转载不要忘了发我的链接

论UITableViewController被status bar覆盖的问题(IOS SDK 8.3)

标签:uiviewcontroller   ios   

原文地址:http://blog.csdn.net/flyback/article/details/46535609

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!