通常我们做一个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];
}
省事罗!
- (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)
原文地址:http://blog.csdn.net/flyback/article/details/46535609