簡體   English   中英

為什么設置barItems不起作用?

[英]Why setting the barItems is not working?

我有一個UIViewController,並將其嵌入到UINavigationController中。

我想在工具欄上顯示一個項目(和工具欄,我的意思是這樣

這是我在viewDidLoad方法中的代碼

self.navigationController?.toolbarHidden = false
self.navigationController?.toolbar.items?.append(UIBarButtonItem(title: "Buy Potato", style: .Plain, target: self, action: #selector(ViewController.buyPotato)))
self.navigationController?.toolbarItems?.append(UIBarButtonItem(title: "Buy Potato", style: .Plain, target: self, action: #selector(ViewController.buyPotato)))     
self.toolbarItems?.append(UIBarButtonItem(title: "Buy Potato", style: .Plain, target: self, action: #selector(ViewController.buyPotato)))

我已經有方法buyPotato

func buyPotato() {

    }

如您所見,我嘗試使用viewController或navigationController做到這一點,但是它不起作用。

我所看到的只是屏幕底部的工具欄,但沒有任何按鈕。

self.navigationController?.toolbarHidden = false
var items = [UIBarButtonItem]()
items.append(
UIBarButtonItem(barButtonSystemItem: .Plain, target: self, action: nil))
items.append(
UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "onClickedToolbeltButton:"))
self.setToolbarItems(barButtonItems, animated: true)

根據這里寫的答案,這必須為您工作。

刪除

self.setToolbarItems(barButtonItems, animated: true)

self.toolbarItems = barButtonItems

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM