Add a navigation bar to a view without a navigation controller

前端 未结 4 1310
情书的邮戳
情书的邮戳 2020-12-09 15:49

I have a side menu that slides out to display a table view and from there I have segues that use the reveal view controller. The segue has to connect directly to the view co

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-09 16:42

    be very careful about adding in "viewWillAppear", as this method can be called more times, (for example is a modal appears....) so use a lazy approach:

    1) declare a var:

    var myNav: UINavigationBar?
    

    2) test if already set:

    viewWillAppear:(BOOL)animated {
    if self.myNav != nil{
         return
    }
    self.myNav = ....
    

    3) be sure remove exiting controller, for example on didDisappear...

    note.. is not correct to specify size.. if iOS rotates, it does not work fine..

提交回复
热议问题