I am unable to add a tool bar to my tableView using the Xcode main.storyboard. Thus, I tried coding it in manually in the viewDidLoad()
我无法使用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
May I know how do I set the logOutButton text and also how to detect if logOutButton has been pressed.
我是否知道如何设置logOutButton文本以及如何检测是否已按下logOutButton。
I tried logOutButton.description = "Log Out"
but it does not work.
我尝试了logOutButton.description =“注销”,但它不起作用。
My toolbar does appear but I have no idea how to add the text for the logout button.
我的工具栏确实出现了,但我不知道如何添加注销按钮的文本。
2 个解决方案
#1
1
The solution is to use UIViewController as parent class and not UITableViewController
解决方案是使用UIViewController作为父类而不是UITableViewController
How to add a toolbar to a TableView in iOS
如何在iOS中向TableView添加工具栏
#2
0
If the TableView happens to be embedded in a Navigation Controller, there is an easy solution: you can add the Toolbar straight away in the NavigationController. The checkbox 'Shows Toolbar' in the Attributes Inspector is all you need. Details: https://*.com/a/34832688/5897915
如果TableView恰好嵌入在导航控制器中,则有一个简单的解决方案:您可以直接在NavigationController中添加工具栏。您只需要在“属性”检查器中选中“显示工具栏”复选框即可。详细信息:https://*.com/a/34832688/5897915
#1
1
The solution is to use UIViewController as parent class and not UITableViewController
解决方案是使用UIViewController作为父类而不是UITableViewController
How to add a toolbar to a TableView in iOS
如何在iOS中向TableView添加工具栏
#2
0
If the TableView happens to be embedded in a Navigation Controller, there is an easy solution: you can add the Toolbar straight away in the NavigationController. The checkbox 'Shows Toolbar' in the Attributes Inspector is all you need. Details: https://*.com/a/34832688/5897915
如果TableView恰好嵌入在导航控制器中,则有一个简单的解决方案:您可以直接在NavigationController中添加工具栏。您只需要在“属性”检查器中选中“显示工具栏”复选框即可。详细信息:https://*.com/a/34832688/5897915