UINavigationItem标题执行操作

时间:2014-07-19 17:21:53

标签: ios xcode ios7 storyboard swift

当点击导航栏的标题时,有什么方法可以让弹出窗口显示(特别是日期选择器)?我实际上正在使用xcode6 / swift,但假设ios7解决方案就足够了!

非常感谢!

2 个答案:

答案 0 :(得分:1)

您需要在内部触摸时创建一个具有特定操作的按钮,然后为navigationItem定义titleView:

self.navigationItem.titleView = yourButton;

现在你有"可触摸"导航标题。

答案 1 :(得分:1)

您可以将按钮设置为title view

override func viewDidLoad() {
    super.viewDidLoad()

    var button:UIButton  = UIButton.buttonWithType(UIButtonType.System) as UIButton

    (button as UIView).frame = CGRectMake(0, 0, 100, 44)
    button.setTitle("Your title", forState: UIControlState.Normal)
    button.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
    self.navigationItem.titleView = button;
}

func buttonClicked(sender:UIButton)
{

    UIAlertView(title: "Message title", message: "POP UP", delegate: nil, cancelButtonTitle: "OK").show()

}
在iOS8中弃用了

修改 UIAlertView <{1}}而是

UIAlertViewController