一直只用他的跳轉(zhuǎn)視圖方式跨算,沒用過他的按鈕之類的论衍,今天用起來挺糾結(jié)的《妫回過頭來再看看
創(chuàng)建一個navigationController 并給他個視圖控制器
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]];
這樣的話 ViewController 就可以在 ViewDidLoad 里面進(jìn)行操作 比如
//設(shè)定標(biāo)題
self.title = @"首頁";
//修改顏色
self.navigationController.navigationBar.tintColor = [UIColor redColor];
//修改為自定義圖片
采用繼承自UINavigationController 然后重寫 - (void)drawRect:(CGRect)rect
//修改右側(cè)的BarButtonItem? 同理可修改左側(cè)按鈕
UIBarButtonItem *callModalViewButton = [[UIBarButtonItem alloc]? initWithTitle:@"按鈕"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(doClicked)];
self.navigationItem.rightBarButtonItem = callModalViewButton;
如果想更改推出來的子類的返回按鈕的話 可以更改 self.navigationItem.backBarButtonItem;
在看 jinglijun 的博客的時候http://blog.csdn.net/jinglijun/article/details/7362329
他提到
用了UINavigationController后萌狂,viewWillAppear方法是沒有效果的档玻,要用UINavigationControllerDelegate的
– navigationController:willShowViewController:animated:? 方法才可以達(dá)到這個目的。
所以要做到這個茫藏,你必須做以下幾步:
1. 設(shè)置代理類 nav.delegate = self;
2. 代理類實現(xiàn)UINavigationControllerDelegate Protocol
3. 在代理類中添加– navigationController:willShowViewController:animated:方法
如:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
[self.myTableView reloadData];
}
但是 我做這個測試了下? 我的無論是父視圖還是子視圖 都會調(diào)用 ViewWillAppear.所以辯證性的看這個問題误趴,等遇到了和jinglijun 一樣的情況就注意下。
隱藏NavigationBar
[self.navigationController setNavigationBarHidden:YES animated:YES];
navigation的推轉(zhuǎn)動畫是可以更改的
CATransition *transition = [CATransitionanimation];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.navigationController.view.layeraddAnimation:transition forKey:nil];
[self.navigationControllerpopViewControllerAnimated:NO];
navigaiton的出棧有這么幾種方式:
[self.navigationController popViewControllerAnimated:YES];? //回到上一個視圖控制器
[self.navigationController popToViewController:viewController animated:YES];? //回到某一個視圖控制器
用法:[self.navigationController popToViewController: [self.navigationController.viewControllers objectAtIndex: ([self.navigationController.viewControllers count] -層次)] animated:YES];
[self.navigationController popToRootViewControllerAnimated:YES]; //回到根視圖控制器