zoukankan      html  css  js  c++  java
  • iOS中设置backBarButtonItem的title和action

    一、 设置title

    在需要显示该返回键的前一个Controller中设置

       1:   navigationItem.backBarButtonItem = UIBarButtonItem(title: "注销", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)

    二、添加返回时执行Action:

    你可以尝试一下在上一行代码中的target和action处填入事件监听的处理方法,但是不会起作用的。

    backBarButtonItem的描述

    Discussion

    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时,自动忽略backBarButtonItem,达到重写backBarButtonItem的目的。

    注意点

    一般我们取导航控制器上的Item这样取:

    navigationItem.backbarItem

    如果这样表示套了两层的导航栏的最外面那层的Item,一般情况下没有这样的嵌套。

    navigationController.navigationItem.backBarButtonItem

    Ref:

    http://blog.csdn.net/dreamno23/article/details/21085783

    http://www.cnblogs.com/ihojin/p/change-backbarbuttonitem-text.html

  • 相关阅读:
    积跬步,聚小流------关于UML类图
    深度学习 Deep Learning UFLDL 最新 Tutorial 学习笔记 1:Linear Regression
    数字语音信号处理学习笔记——语音信号的短时频域分析(2)
    PHP程序猿必须学习的第二课——站点安全问题预防
    Connection for controluser as defined in your configuration failed.
    NYOJ 76 超级台阶
    单片机小白学步系列(十) 单片机程序下载相关知识
    SQL 语言划分
    UVA 11754
    客户端远程方法声明
  • 原文地址:https://www.cnblogs.com/zeyang/p/4493692.html
Copyright © 2011-2022 走看看