zoukankan      html  css  js  c++  java
  • 关于Navigation的BarButtonItem的

    (ios6.1)有两个controller在navigation stack里,A和B。A是B的previous view controller,现在top-level controller是B。要自定义B的backBarButtonItem。

    在B的viewDidLoad里添加:

    1     //chage navigationBarButton
    2     UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"房间选择" style:UIBarButtonItemStyleDone target:nil action:nil];
    3     [self.navigationItem setBackBarButtonItem:backButtonItem];

    试了,结果还是默认的back按钮。

    UINavigationController Class Reference中有段话:

    The bar button item on the left side of the navigation bar allows for navigation back to the previous view controller on the navigation stack. The navigation controller updates the left side of the navigation bar as follows:

    • If the new top-level view controller has a custom left bar button item, that item is displayed. To specify a custom left bar button item, set the leftBarButtonItem property of the view controller’s navigation item.
    • If the top-level view controller does not have a custom left bar button item, but the navigation item of the previous view controller has a valid item in itsbackBarButtonItem property, the navigation bar displays that item.
    • If a custom bar button item is not specified by either of the view controllers, a default back button is used and its title is set to the value of the title property of the previous view controller—that is, the view controller one level down on the stack. (If there is only one view controller on the navigation stack, no back button is displayed.)
    • 1、如果B视图有一个自定义的左侧按钮(leftBarButtonItem),则会显示这个自定义按钮;

      2、如果B没有自定义按钮,但是A视图的backBarButtonItem属性有自定义项,则显示这个自定义项;

      3、如果前2条都没有,则默认显示一个后退按钮,后退按钮的标题是A视图的标题,或者默认

    try again,在A中的ViewDidLoad中定义backButtonItem:

    1     //chage navigationBarButton
    2     UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"房间选择" style:UIBarButtonItemStyleDone target:nil action:nil];
    3     [self.navigationItem setBackBarButtonItem:backButtonItem];

    发现B中的backBarButtonItem改变了!!!

    如果在B中custom一个UIbarButtonItem,赋值给self.navigationItem.leftBarButtonItem,那么这个UIBarButtonItem将替换backBarButtonItem按钮。

  • 相关阅读:
    kendo ui 查找treelist里的子控件并设置是否显示的方法
    KendoUi下的DatePicker在谷歌浏览器上不能正常显示时间的解决方法
    asp.net 第三方UI控件 Telerik KendoUI 之 TreeVIew 的用法记录
    mysql批量更新数据,即:循环select记录然后更新某一字段
    Sql语句备份Sqlserver数据库
    3des用法示例,已测试
    制作Windows服务项目详细攻略
    利用好压在C#程序里实现RAR格式的压缩和解压功能
    winform里textBox无法获得焦点的解决方案
    Shell脚本批量重命名案例
  • 原文地址:https://www.cnblogs.com/hereiam/p/3888599.html
Copyright © 2011-2022 走看看