2015-05-19 63 views
2

我試圖將UIBarButtonItem添加到UINavigationController的工具欄,但它沒有顯示任何按鈕,並且發現_toolbar陣列在我進行調試時爲空。無法將UIBarButtonItem添加到UINavigationController的工具欄中

override func viewDidLoad() { 
     var default_title = ["A","B"," C","D"] 
     var items: NSArray = NSArray() 
     for title in default_title 
     { 
      items.arrayByAddingObject(UIBarButtonItem(title: title, style: UIBarButtonItemStyle.Bordered, target: self, action: "")) 
     } 

     self.setToolbarItems(items as [AnyObject], animated: true) 
     self.setToolbarHidden(false, animated: false) 
} 

回答

3

我發現問題是items應該是Array<UIBarButtonItem>

代碼:

override func viewDidLoad() { 
    var default_title = ["A","B"," C","D"] 
     var items: Array<UIBarButtonItem> = [] 
     for title in default_title 
     { 
      items.append(UIBarButtonItem(title: title, style: UIBarButtonItemStyle.Bordered, target: self, action: "")) 
     } 

     self.setToolbarItems(items as [AnyObject], animated: true) 
     self.setToolbarHidden(false, animated: false) 
} 
相關問題