What is a good way to get a popup to appear (specifically a date picker) when I tap the title of my navigation bar? I'm actually using xcode6/swift but assume an ios7 solution would suffice!
Thanks so much!
What is a good way to get a popup to appear (specifically a date picker) when I tap the title of my navigation bar? I'm actually using xcode6/swift but assume an ios7 solution would suffice!
Thanks so much!
You need to make a button with the specific action on touch up inside and then define titleView for navigationItem:
self.navigationItem.titleView = yourButton;
Now you have "touchable" navigation title.
You can set button as 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()
}
Edit UIAlertView
deprecated in iOS8.Using UIAlertViewController
instead
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)
}