- (void)goBackAction {
[self.navigationController popViewControllerAnimated:YES];
引发问题:leftBarButtonItem与backBarButtonItem有何区别
他们都属于UINavigationItem的组成部分,都显示在navigationBar上,都属于UIBarButtonItem类
backBarButtonItem和leftBarButtonItem RightBarButtonItem是有区别的
区别:
如果A控制器准备Push到B控制器上,设置backBarButtonItem的title和image需要在A控制器内设置,在调用A控制器push出B之前设置,A.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle…..]
而leftItem与rightItem则是在BController的ViewDidLoad后设置均可。
总结:back是push前,本控制器想设置在下一个控制器中的后退显示, 而left与right是push出来的控制器设置
接下来是一段摘自backBarButtonItem文档上的话:
When this navigation item is immediately below the top item in the stack, the navigation controller derives the back button for the navigation bar from this navigation item. When this property is nil, the navigation item uses the value in its title property to create an appropriate back button. If you want to specify a custom image or title for the back button, you can assign a custom bar button item (with your custom title or image) to this property instead. When configuring your bar button item, do not assign a custom view to it; the navigation item ignores custom views in the back bar button anyway.
大概说明了:backBarButtonItem只能自定义image和title,不能重写target or action,系统会忽略其他的相关设置项。如果需要重写action,则需要自定义一个leftBarButtonItem,因为系统定义leftBarButtonItem的显示优先级比backBarButtonItem优先级高,当存在leftBarButtonItem时,自动忽略backButtonItem,达到重写backBarButtonItem的目的。
引伸:以下三个的区别
AF:self.navigationItem.backBarButtonItemBF:self.navigationController.navigationItem.backBarButtonItemCF:self.navigationController.navigationBar.backItem.backBarButtonItem
比如A控制器push出B控制器,在A设置了AF,经过试验发现,这个backBarButtonItem为B控制器的CF
@property(nonatomic, readonly, retain)UINavigationItem *navigationItem
UIViewController的属性navigationItem正是被当前UINavigationBar——[UINavigationBar appearance]管理的属性。
self.navigationController.navigationItem.backBarButtonItem
则是表示当前navigationController的parent的UINavigationBar,一般情况下没有这样的嵌套。
问题:push一个控制器时,如果要将其tabBar不再展示,而返回时再展示,设置如下即可,在push之前
1 . 创建一个即将Push的控制器:
RegisterViewController *registerVC = [[RegisterViewController alloc] init];
2 . 设置其push时为隐藏Bar
registerVC.hidesBottomBarWhenPushed = YES;
3 . 设置当前控制器显示Bar(关键)
self.hidesBottomBarWhenPushed = NO;
4 . push(在此之后,所有的都不会有控制器)
[self.navigationController pushViewController:registerVC animated:YES]
补充:
如果要设置backBarItem不能只用alloc init不然便没有效果,需大致如下(属性要创建):
UIBarButtonItem *backI = [[UIBarButtonItem alloc] initWithTitle:@"我的" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backI;
tabBar与navigation使用注意点:往往都是从需求而迸发出问题所在的。问题展开:需要自定义导航栏上的返回按钮样式?可以在navigationController控制器中进行重写方法,设置其backItem共需要四步:1 . 设置backButtonItem属性隐藏 self.navigationItem.hidesBackButton = YES;2 . 自定义一个btn UIBut
//1.在当前视图控制器中写了如下代码:
UIBarButtonItem *back = [[UIBarButtonItem alloc]initWithTitle:@”QQ” style:UIBarButtonItemStyleDone target:nil action:nil];
//导航控制器除了根视图外其他子视图控制器都默认有一个左侧返回按钮。
self.navigationItem
1. 后退按钮BackBarButtonItem的title设置想要导航栏中后退按钮(带箭头,BackBarButtonItem)和BarButtonItem的文字,折腾了一会,试了几种方法都不奏效,最终找到了个解决办法。
如果APP通过navigationController从A视图跳转至B视图,导航的返回按钮的加载原理是这样的:
1、如果B视图有一个自定义的左侧按钮(leftBarBu
在开发里,遇到了需要在导航栏里的返回按钮里做很多自定义的事情,比如说根据某个状态判断返回的是哪个页面
iOS导航栏中的返回按钮最多就改改样式啥的,但是无法获取点击事件,更别说修改了。。
收集了很多资料之后,终于在项目里实现了效果,于是下面就整理一下关于backButton的事,方便日后使用~
一、关于自定义的backButton
很多时候我们只需要去改变backButton的样式而
iOS8设置NavigationBar颜色和BackButtonItem颜色,归档存储以备查阅,把以下代码添加到appdelegate的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions//1. 设置导航栏的背景图片
UINavig
self.navigationController.navigationItem = customItem;
self.navigationItem = customItem;
我们都知道navigationItem是UIViewContro