ios - UINavigationItem 标题执行操作

标签 ios xcode ios7 storyboard swift

当我点击导航栏的标题时,有什么好方法可以让弹出窗口(特别是日期选择器)出现?我实际上使用的是 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/

相关文章:

ios - iOS 6 和 iOS 7 在模拟器中的显示屏幕不同

ios - UITabBarController - 子(选项卡)ViewControllers 的不正确和不一致的边界

ios - 将 View Controller 保持在与左侧相同的位置

iphone - 在 ios 中直接使用 writestream 到 IP 和端口

ios - 我们如何远程关闭推送通知?

ios - 从 xcode 中的 mainBundle 获取子目录

ios - 整洁架构 : Interactor logic on the server

ios - Xcode 的界面生成器中是否有针对较小 iPhone 的尺寸变体?

xcode - 是否可以在构建 Xcode 项目时转储 AST?

ios - 仅适用于iOS7用户在App Store上提交现有应用的新版本。可能吗?