【问题标题】:use segue with kind present modally by code通过代码以模态方式使用带有种类的 segue
【发布时间】:2016-08-21 07:51:44
【问题描述】:

我有custom navigation bar 并且有一个按钮栏 我需要使用present modally 类型从我的栏按钮到我的自定义导航创建segue,但以编程方式不是来自情节提要 这项工作但segue类型是push

self.navigationController?.pushViewController("", animated: true)

我应该怎么做才能得到它present modally

【问题讨论】:

  • 你的故事板截图?
  • 根据您的描述,您希望以present modally 方式显示控制器。对吗?

标签: ios swift navigationcontroller


【解决方案1】:

这是一个简单的解决方案,使用 NavigationController 以模态方式呈现。

yourviewcontroller *myviewc= [[yourviewcontroller alloc] init];
[self presentViewController:myviewc animated:YES completion:nil];

如果你有一个导航控制器,第二个。

let myvc= self.storyboard!.instantiateViewControllerWithIdentifier("MyViewController") as! ViewController
    let navc= UINavigationController(rootViewController: myvc) 
    self.presentViewController(navc, animated:true, completion: nil)

您只需为您的 Button 创建一个 IBAction。本教程可以帮助你做到这一点IBAction

希望对您有所帮助!

【讨论】:

  • 我应该在哪里写 AddTaskViewController ...
  • 它是您想要以模态方式显示的视图控制器!
【解决方案2】:

根据您的描述,您希望以present modally 方式显示控制器。添加 UIButton 或类似 UIButton(UIBarButtonItem) 的东西。

这个怎么样:

override func viewDidLoad() {
    super.viewDidLoad()

    let rightButton = UIBarButtonItem(title: "present", style: .Plain, target: self, action: #selector(clickRightItem))
    navigationItem.rightBarButtonItem = rightButton;
}

func clickRightItem() {
    let controllerToPresent = UIViewController()
    controllerToPresent.view.backgroundColor = UIColor.redColor()
    presentViewController(controllerToPresent, animated: true, completion: nil)

}

【讨论】:

  • 是的,但我想以编程方式进行
猜你喜欢
  • 2020-08-12
  • 2013-09-20
  • 2015-07-21
  • 2013-11-23
  • 1970-01-01
  • 1970-01-01
  • 2020-10-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多