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

通常我们做一个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];
}

感谢一下我吧!

转载不要忘了发我的链接

时间: 2024-10-13 21:21:14

论UITableViewController被status bar覆盖的问题(IOS SDK 8.3)的相关文章

iOS开发-UINavigationBar和Status Bar实用技巧

iOS7之后关于UINavigationBar和Status  Bar都发生了一系列的改变,如果不需要兼容iOS7之后的设备,按照网上有些资料去解决问题会踩到一些坑.在iOS 7中,我们可以修改每个View Controller中状态栏的外观,而iOS7之前的状态栏都是白色风格.iOS7之前设置背景颜色还需要搞个背景View覆盖,而iOS7只需要设置一下barTintColor颜色即可. UINavigationBar设置 1.设置背景颜色: [self.navigationController

与Status Bar和Navigation Bar相关的一些东西

与StatusBar和NavigationBar相关的东西有两种,一是控制它们的显示与隐藏,二是控制它们的透明与否及背景. 在2.3及以前,StatusBar只能显示与隐藏,即全屏模式,通过WindowManager.LayoutParams.FLAG_FULLSCREEN来实现: getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 并可通过以下Flag使Activity的布局可以使用整个屏幕,状态栏会显示到Acti

iOS7下隐藏status bar的详细研究

info.plist文件中,View controller-based status bar appearance项设为YES,则View controller对status bar的设置优先级高于application的设置.为NO则以application的设置为准,view controller的prefersStatusBarHidden方法无效,是根本不会被调用的. 1.View controller-based status bar appearance设为YES. 这时 view

iOS开发UI篇— View controller-based status bar appearance

info.plist文件中,View controller-based status bar appearance项设为YES,则View controller对status bar的设置优先级高于application的设置.为NO则以application的设置为准,view controller的prefersStatusBarHidden方法无效,是根本不会被调用的. 一.如果View controller-based status bar appearance 设为YES. 这时 vi

改变status bar的状态

两种改变status bar状态的方法 一 :(全局的) 直接在当前控制器中(一般是在navigationcontroller) //- (UIStatusBarStyle)preferredStatusBarStyle{ //    return UIStatusBarStyleLightContent; //} 二 :(可以更具需要改变状态栏显示效果 //代码如下 [UIApplication sharedApplication].statusBarStyle = UIStatusBarSt

WP 8.1 status bar

A status bar is the bar showing signal, battery and time on the top of the phone's screen. In WP8.1 we it's called status bar, but in WP8.0 it's called phone shell. Show progress bar in the status bar: var statusBar = Windows.UI.ViewManagement.Status

status bar、navigationBar、tableView吸顶view设置

1. 隐藏navigationBar self.navigationController.navigationBar.hidden = YES; 2. status bar设置 -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; } -(void)v

Keyboard、In-Call Status Bar的监听及视图位置改变调整(实例说明)

写于前: 当有textField的时候,键盘出现时,需要改变其他视图的frame,以及来电时In-Call Status Bar的出现也会影响其他视图的frame,那么通过通知模式,来观察两者的变化,并当其变化时进行一些操作. 代码思路:(视图frame的调整,以创建一个简单toolBar为例来实现) 1.底栏的创建,其中textField设置代理,遵循 2.UITextFieldDelegate协议,设置点击return返回键盘消失 3.通知的注册 4.通知的移除,在viewWillDisap

iOS7隐藏状态栏 status Bar

转自:http://blog.csdn.net/dqjyong/article/details/17896145 IOS7中,不仅应用的风格有一定的变化,状态栏变化比较大,我们可以看到UIVIEWCONTROLLER的状态栏与导航栏基本是一体的.因此UIVIEWCONTROLLER的HIDE/SHOW状态的方法也跟其他版本的不一样了. 在IOS7以前的版本,HIDE/SHOW是通过以下代码实现 [cpp] view plaincopy [[UIApplication sharedApplicat