gpt4 book ai didi

ios - 如何显示导航左栏按钮?

转载 作者:可可西里 更新时间:2023-11-01 00:20:31 25 4
gpt4 key购买 nike

使用 Xcode 9.3 版 Swift 开发 iOS 应用程序。

导航左栏按钮不出现。你能告诉我如何显示左栏按钮吗?

当我用相同的代码尝试右侧的按钮时,它显示没有任何问题。

代码和 Storyboard如下。

第一个TableView代码

import UIKit

class TableViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()

let naviButton = UIBarButtonItem(title: "naviButton", style: UIBarButtonItemStyle.plain, target: self, action: #selector(Tapped))

// Left bar button does not appear
self.navigationItem.leftBarButtonItem = naviButton

// Right bar button do appear
self.navigationItem.rightBarButtonItem = naviButton

// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}

@objc func Tapped() {
print("Tapped")
}

...

Storyboard

Storyboard

模拟器

enter image description here

最佳答案

You can not place same button twice in UINavigationBar. So create 2 separate button and then assign them to leftbarButton and rightbarButton:

override func viewDidLoad() {
super.viewDidLoad()

let leftNaviButton = UIBarButtonItem(title: "lNaviButton", style: UIBarButtonItemStyle.plain, target: self, action: #selector(Tapped1))
self.navigationItem.leftBarButtonItem = leftNaviButton

let rightNaviButton = UIBarButtonItem(title: "rNaviButton", style: UIBarButtonItemStyle.plain, target: self, action: #selector(Tapped2))
self.navigationItem.rightBarButtonItem = rightNaviButton
}

@objc func Tapped1() {
print("Tapped1")
}

@objc func Tapped2() {
print("Tapped2")
}

关于ios - 如何显示导航左栏按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49654754/

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