gpt4 book ai didi

ios - 无法以编程方式在 Swift 导航栏上生成 "< Back"

转载 作者:行者123 更新时间:2023-11-30 10:04:57 24 4
gpt4 key购买 nike

首先让我说我正在以编程方式完成所有编码。我的问题是我无法在导航栏中生成经典的 iOS“

这是我用来创建导航栏的函数:

// Makes a navigation Bar
func makeNavigationBar(navigationBar: UINavigationBar, barTitle: String, forwardButton: Bool, backButton: Bool, page: UIViewController){
// Create a navigation item with a title
let navigationItem = UINavigationItem()
navigationItem.title = barTitle

// Create left navigation item
if(backButton){
let leftButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: page, action: "backClicked:")
// Create two buttons for the navigation item
navigationItem.leftBarButtonItem = leftButton
}
if(forwardButton){
let rightButton = UIBarButtonItem(title: "Next", style: UIBarButtonItemStyle.Plain, target: page, action: "nextClickedClicked:")
// Create two buttons for the navigation item
navigationItem.rightBarButtonItem = rightButton
}
// Assign the navigation item to the navigation bar
navigationBar.items = [navigationItem]
//Adds the bar to the view
page.view.addSubview(navigationBar)
}

这是我对该函数的调用:

let navigationBar = UINavigationBar(frame: CGRectMake(0, 0, self.view.frame.size.width, height/12)) 
creationFunctions.makeNavigationBar(navigationBar, barTitle: "", forwardButton: false, backButton: true, page: self)

这是“backClicked”函数:

func backClicked (sender: UIBarButtonItem!){
self.dismissViewControllerAnimated(true, completion: {});
}

感谢您的帮助。

最佳答案

您好,这是创建自定义后退按钮并将其添加到 navigationController 的代码。我的 ViewController 类中有这些方法。

func addBackButton() {
let image = UIImage(named: "BackImage")!.imageWithRenderingMode(.AlwaysOriginal)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: image, style: .Plain, target: self, action: "backClicked:")
}

func backClicked (sender: UIBarButtonItem!){
self.dismissViewControllerAnimated(true, nil);
}

希望对你有帮助

关于ios - 无法以编程方式在 Swift 导航栏上生成 "< Back",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36508148/

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