当我点击导航栏的标题时,有什么好方法可以让弹出窗口(特别是日期选择器)出现?我实际上使用的是 xcode6/swift,但假设 ios7 解决方案就足够了!
非常感谢!
最佳答案
您可以将按钮设置为标题 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)
}
关于ios - UINavigationItem 标题执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24842997/