gpt4 book ai didi

快速,嵌入带有导航 Controller 的 ui View Controller 以允许后退按钮

转载 作者:行者123 更新时间:2023-11-30 11:47:08 26 4
gpt4 key购买 nike

我正在尝试在 MyServiceTypeSelector() Controller 上获取后退按钮,以便在呈现 MyServiceTypeSelector() 后我可以返回到 BRPServiceSelector() Controller ,我该如何执行此操作?我是否需要将其嵌入导航 Controller ,如果是这样,我不使用 Storyboard,因此需要以编程方式完成?

 import Foundation
import UIKit

class BRPServiceSelector: UIViewController, UITextFieldDelegate {


override func viewDidLoad() {
super.viewDidLoad()

setupViews()



}



let businessAccountLabel: UILabel = {
let label = UILabel()
label.text = "Business Account"
label.backgroundColor = .white
label.translatesAutoresizingMaskIntoConstraints = false
label.textAlignment = .center
return label
}()







lazy var serviceSelectorButton: UIButton = {
let button = UIButton(type: .system)
button.backgroundColor = UIColor.black
button.setTitle("Select A Service Type?", for: .normal)
button.setTitleColor(UIColor.white, for: .normal)
button.addTarget(self, action: #selector(presentServiceSelector), for: .touchUpInside)
button.layer.cornerRadius = 3
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)

return button
}()


func presentServiceSelector(){

let msts = MyServiceTypeSelector()
let navController = UINavigationController(rootViewController: msts)
self.present(navController, animated: true, completion: nil)







let containerView: UIView = {
let v = UIView()
v.translatesAutoresizingMaskIntoConstraints = false
v.backgroundColor = .white
return v
}()





let scrollView: UIScrollView = {
let v = UIScrollView()
v.translatesAutoresizingMaskIntoConstraints = false
v.backgroundColor = .white
return v
}()


func setupViews(){

containerView.addSubview(serviceSelectorButton)

serviceSelectorButton.anchor(top: containerView.topAnchor, left: nil, bottom: nil, right: nil, paddingTop: 50, paddingLeft: 0, paddingBottom: 0, paddingRight: 0, width: 220, height: 25)

serviceSelectorButton.centerXAnchor.constraint(equalTo: containerView.centerXAnchor).isActive = true
}
}

}

最佳答案

如果您希望 VC 位于导航堆栈中,请将其插入堆栈而不是呈现它。呈现通常用于模式窗口,它们通常没有导航栏。

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

关于快速,嵌入带有导航 Controller 的 ui View Controller 以允许后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48702859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com