0

JSQmessageViewControllerを使用していて、ナビゲーションバーに「戻る」ボタン&のユーザー画像をプログラムで追加しようとしています。私は次のコードを使用しています。それを実行した後、 "戻る"ボタンや画像はありません。添付されているのは、シミュレータのスクリーンショットです。私は通常のUIViewControllerでこれらのコードをテストし、彼らは働いた。JSQmessageView Controller:Swiftのナビゲーションバーに「戻る」ボタンと画像を追加

なぜJSQmessageViewControllerで動作しないのか分かりますか?ナビゲーションバーに「戻る」ボタン&イメージを追加するにはどうすればよいですか?どうもありがとう!

let navigationBar = UINavigationBar(frame: CGRectMake(0, 0, self.view.frame.size.width, 64)) 

    navigationBar.backgroundColor = UIColor.whiteColor() 
    navigationBar.delegate = self; 


    let navigationItem = UINavigationItem() 
    navigationItem.title = strValue 

    let leftButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "back:") 
    self.navigationItem.leftBarButtonItem = leftButton 

    let imgButton = UIButton() 

    imgButton.setImage(image, forState: .Normal) 
    imgButton.addTarget(self, action: "EditProfile:", forControlEvents: UIControlEvents.TouchDown) 
    imgButton.frame = CGRectMake(self.view.frame.width - 60, 0, 41, self.view.frame.height) 

    var rightButton = UIBarButtonItem(customView: imgButton) 

    self.navigationItem.rightBarButtonItem = rightButton 


    navigationBar.items = [navigationItem] 

    self.view.addSubview(navigationBar) 

}

+0

添付のスクリーンショットが表示されません。 –

答えて

0

あなたがJSQMessagesViewControllerのあなたのインスタンス化を提示するナビゲーションコントローラを使用するのであれば、その後のナビゲーションバーには、実際に既に存在する必要があります。それらのボタンを提供するだけで、正しい場所に配置されます。また、古くなった構文で作業をしているようです。ここに最新の構文があります。

戻るボタンを追加する関数を作成します。

func addCancelButtonLeft() { 
    let button = UIBarButtonItem(barButtonSystemItem: .back, target: self, action: #selector(dismissView)) 
    navigationItem.leftBarButtonItem = button 
} 

ボタンのアクションを作成します。

func dismissView() { 
    dismiss(animated: true, completion: nil) 
} 

は、その後、あなたのイメージのためにあなたが実際にそのタイトル・ビューにボタンを配置しようとしています。どちらが良いですか。

func titleView() { 
    let imgButton = UIButton() 

    imgButton.setImage(image, forState: .Normal) 
    imgButton.addTarget(self, action: #selector(EditProfile), forControlEvents: .touchUpInside) 
    navigationItem.titleView = imgButton 
} 
func EditProfile() { 
    navigationController?.present(EditProfileViewController(), animated: true, completion: nil) 
} 

質問が多い場合はお知らせください。幸運

+0

詳細なコードとヘルプをありがとうございました。それらを試してさらに学ぶでしょう。 :) –

関連する問題