我无法将barButton项添加到navigationBar

时间:2019-06-25 14:35:17

标签: ios interface-builder uinavigationbar

我在RestClient esClient = RestClient.builder(new HttpHost("localhost", 9200, "http")).build(); Request request = new Request("POST", "/INDEX_NAME/_doc/_search"); request.setJsonEntity(yourJsonQueryString); Response response = esClient.performRequest(request); String jsonResponse = EntityUtils.toString(response.getEntity()); 中嵌入了ViewController,此后,我添加了一个新的UINavigationController,并用segue将其连接到嵌入在其中的第一个ViewController ViewController。然后我想在第二个视图中添加一个UINavigationController,但是当我放开视图顶部标题旁边的条形按钮项时,它将其插入按钮中,然后在运行该应用程序时仅在第一个屏幕和标题上显示后退按钮。 (请参见运行时的外观以及将其插入顶部后的外观图片)running the app in the iPad simulator how the interface-builder looks after inserting the barbuttonitem to the top

希望您能理解这个问题,并且可以帮助我!

提前谢谢!

Benji

1 个答案:

答案 0 :(得分:0)

在要添加按钮的控制器的viewDidLoad方法中编写此代码

    let navBtn = UIButton(type: .custom)
    navBtn.setImage(UIImage(named: "side_drawer"), for: .normal)
    navBtn.frame = CGRect(x: 0, y: 0, width: 40, height: 100)
    navBtn.addTarget(self, action: #selector(openMessagingThread(_:)), for: .touchUpInside)
    let rightNavBarItem = UIBarButtonItem(customView: navBtn)
    self.navigationItem.setRightBarButton(rightNavBarItem, animated: true)

// barButton的动作

   @objc
func openMessagingThread(_ sender: UIButton)  {

}
相关问题