【发布时间】:2014-09-10 15:41:33
【问题描述】:
当我点击导航栏的标题时,让弹出窗口(特别是日期选择器)出现的好方法是什么?我实际上使用的是 xcode6/swift 但假设 ios7 解决方案就足够了!
非常感谢!
【问题讨论】:
标签: ios xcode ios7 storyboard swift
当我点击导航栏的标题时,让弹出窗口(特别是日期选择器)出现的好方法是什么?我实际上使用的是 xcode6/swift 但假设 ios7 解决方案就足够了!
非常感谢!
【问题讨论】:
标签: ios xcode ios7 storyboard swift
您可以将按钮设置为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()
}
编辑 UIAlertView 在 iOS8 中已弃用。请改用 UIAlertViewController
func buttonClicked(sender:UIButton)
{
var alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
【讨论】:
customContentView 是您的日期选择器
您需要在里面制作一个带有特定动作的按钮,然后为navigationItem定义titleView:
self.navigationItem.titleView = yourButton;
现在你有了“可触摸”的导航标题。
【讨论】: