Swift:将工具栏和工具栏按钮项添加到 Table 视图

Swift: Adding a toolbar and tool bar button item to a Table View

我无法使用 Xcode main.storyboard 向我的 tableView 添加工具栏。 因此,我尝试在 viewDidLoad()

中手动编码
    let logOutButton = UIBarButtonItem(title: "Log Out", style: UIBarButtonItemStyle.Bordered, target: self, action: "logOut")
    var bottomBarButtonArray = [UIBarButtonItem]()
    bottomBarButtonArray.append(logOutButton)

    self.navigationController!.setToolbarHidden(false, animated: true)

    self.navigationController!.toolbar.items = bottomBarButtonArray

请问如何设置 logOutButton 文本以及如何检测是否已按下 logOutButton。

我尝试了 logOutButton.description = "Log Out" 但它不起作用。

我的工具栏确实出现了,但我不知道如何为注销按钮添加文本。

解决方案是使用 UIViewController 作为父级 class 而不是 UITableViewController

How to add a toolbar to a TableView in iOS

如果 TableView 恰好嵌入在导航控制器中,有一个简单的解决方案:您可以直接在导航控制器中添加工具栏。 Attributes Inspector 中的复选框 'Shows Toolbar' 就是您所需要的。 详情: