2017-02-11 12 views
0

私のサブクラスであるUIViewControllerには、ナビゲーションコントローラに埋め込まれたviewDidLoadオーバーライドがあります。私はツールバーを非表示にしていますが、実行するとツールバーが表示されます(ナビゲーションコントローラ内にあることを確認し、正しくアドレス指定しています)。しかし、表示するボタンはありません。私はここで間違って何をしていますか?Swift:UINavigationControllerツールバーのツールバーボタンの追加に問題があります

override func viewDidLoad() { 
    super.viewDidLoad() 

    var buttons = [UIBarButtonItem]() 
    for title in buttonTitleArray { 
     let plainButton = UIBarButtonItem(title: title, style: .plain, target: self, action: #selector(self.setContentMode(_:))) 
     let systemButton = UIBarButtonItem(barButtonSystemItem: .play, target: self, action: #selector(self.setContentMode(_:))) 
     buttons.append(plainButton) 
     buttons.append(systemButton) 
    } 
    self.navigationController?.toolbarItems = buttons 
    self.navigationController?.isToolbarHidden = false 
} 

self.navigationController?.setToolbarItems(buttons, animated: false)を使用してボタンを追加しようとしましたが、どちらも機能しません。

+0

あなたは、ナビゲーションバーのボタン(カスタム/システム)を追加しようとORナビゲーションバーのツールバーを設定していますか? –

+0

私は、ウィンドウの下部にツールバーを追加しようとしています。追加しようとしている2つのボタンが混乱している場合は、ツールバーのボタンを使用していないので、これをやっているので、単純なものが何であるかを見たいと思っていました。つまり、タイトルごとに2つのボタンを作っているという事実を無視することができます。 –

答えて

0

ビューにツールバーのボタンを表示するには、コードの下にしてみてください: -

var items = [UIBarButtonItem]() 

    //Custom Button 
    let plainButton = UIBarButtonItem(title: "Test", style: .Plain, target: self, action: #selector(self.customButtonTapped)) 
    items.append(plainButton) 

    //Add Flexible space between buttons 
    let flexibalSpace = UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: self, action: nil) 
    items.append(flexibalSpace) 

    //Toolbar system button 
    let systemButton = UIBarButtonItem(barButtonSystemItem: .Play, target: self, action: #selector(self.systemButtonTapped)) 
    items.append(systemButton) 

    self.toolbarItems = items //Display toolbar items. 
    self.navigationController?.toolbarHidden = false 
+0

ありがとうございます。私の問題は、self.toolBarItemsではなくnavigationController.toolbarItemsにボタンを追加していたようです –

関連する問題