UIBarButtonItem、UINavigationController

//在AppDelegate.m中
 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor redColor];
   
    //创建一个视图控制器(创建之初就加载nib)
    OneViewController *oneVC = [[OneViewController alloc]initWithNibName:@"OneViewController" bundle:nil];
   
    //oneVC控制器的对象放在一个导航控制器的栈底(因为栈内存中只有这一个对象,栈底也就是栈顶,栈顶就是优先显示与窗口之上的对象)
    UINavigationController *navc = [[UINavigationController alloc]initWithRootViewController:oneVC];
//    [navc pushViewController:oneVC animated:YES];
    //窗口的根视图控制器接收navc(navc的类继承自UIViewController)
    self.window.rootViewController = navc;
   
    //窗口展示在屏幕的最前端
    [self.window makeKeyAndVisible];
    
    return YES;
}
/****************************************************************/
//通过pushViewController方法压栈
    [self.navigationController pushViewController:twoVC animated:YES];
//出栈的方式:
 
    //直接出栈,一直到栈底(仅剩一个控制器的时候)
    [self.navigationController popToRootViewControllerAnimated:YES];
   
    //指定栈内存中的某个控制器
    [self.navigationController popToViewController:fiveVC animated:YES];
    //一个一个的出栈
    [self.navigationController popViewControllerAnimated:YES];
/****************************************************************/
《UIBarButtonItem》:
 
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithTitle:@"返回吗" style:UIBarButtonItemStylePlain target:self action:@selector(doReturn)];
    self.navigationItem.leftBarButtonItem = leftItem;
   
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    self.navigationItem.rightBarButtonItem = rightItem;
   
    //显示副标题
    self.navigationItem.prompt = @"hello";
 
posted @ 2015-11-23 21:35  开心刘哈哈  阅读(185)  评论(0编辑  收藏  举报