在 Segue 视图上的导航栏添加按钮

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

您能告诉我如何向模态视图添加按钮吗?我希望它是这样的:

我尝试了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 uinavigationbar segue
1个回答
0
投票

这个问题从一开始就说错了。不存在“Segue View”这样的东西,它是 View 的模态呈现。 标准的 navigationItem 方法不适用于模式呈现。因此,添加这样的按钮的唯一方法是使用 UIButton 手动: let addButton = UIButton() let cancelButton = UIButton() override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white view.addSubview(addButton) addButton.setTitle("Add", for: .normal) addButton.titleLabel?.font = .systemFont(ofSize: 17, weight: .semibold) addButton.setTitleColor(.systemOrange, for: .normal) addButton.snp.makeConstraints { make in make.top.equalToSuperview().inset(10) make.right.equalToSuperview().inset(15) } view.addSubview(cancelButton) cancelButton.setTitle("Cancel", for: .normal) cancelButton.titleLabel?.font = .systemFont(ofSize: 17, weight: .semibold) cancelButton.setTitleColor(.systemOrange, for: .normal) cancelButton.snp.makeConstraints { make in make.top.equalToSuperview().inset(10) make.left.equalToSuperview().inset(15) }

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