在模态呈现的 UIViewController 上向 UINavigationController 添加按钮

问题描述 投票:0回答:1

你能告诉我如何向模式添加按钮吗

View
?我希望它是这样的:

我尝试了navigationItem方法,但它似乎不起作用。

navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addNewBDay))

我根本不使用故事板,所以我以这种方式呈现模态视图

let openNextScreen = UIButton()

openNextScreen.addTarget(self, action: #selector(presentModal()), for: .touchUpInside)

@objc func presentModal() {
   let secondScreen = SecondViewController()
   self.navigationController?.present(secondScreen, animated: true)
   print("DEBUG: presentation working")
}
ios swift uinavigationcontroller uibutton uinavigationbar
1个回答
0
投票

这个问题从一开始就说错了。不存在“Segue View”这样的东西,它是 View 的模态呈现。 在模态呈现中添加单独的UINavigationViewController

View

(如果我正确理解了术语)
有帮助:
家长View

NavigationViewController

import UIKit
import SnapKit

class ViewController: UIViewController {
   //some code
}

@objc func addNewBDay() {
   let secondVC = SecondScreen()
   let nextScreen = UINavigationController(rootViewController: secondVC) // adding own NavigationController to modally presented View
   self.navigationController?.present(nextScreen, animated: true)
}

View
NavigationViewController

以模态方式呈现:
import UIKit
import SnapKit

class SecondScreen: UIViewController {
   override func viewDidLoad() {
      super.viewDidLoad()
      navigationItem.title = "Navbar Header"
      navigationItem.rightBarButtonItem = setUpSaveButton()
   }
}
    

© www.soinside.com 2019 - 2024. All rights reserved.