Home  >  Q&A  >  body text

ios - vc中present了一个带nav的vc,但是弹出的vc不能设置其nav的titile和baritem?

如题,present的代码是这样的

UINavigationController* cityListNav = [[UINavigationController alloc]initWithRootViewController:cityList];
   /*
    cityListNav.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"ic_me_back"] style:UIBarButtonItemStylePlain target:self action:@selector(closeCityList)];
    */
    cityListNav.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回"style:UIBarButtonItemStyleDone target:self action:@selector(closeCityList)];

    cityListNav.navigationBar.backgroundColor = [UIColor whiteColor];
    cityListNav.title = @"城市选择";

     [self presentViewController:cityListNav animated:YES completion:nil];

无论在present的vc内外设置nav都没有反应,无论什么方式添加leftbaritem也都没有反应好,只有background可以。。。。
一开始我以为是特例,在别的控制器present了一个别的带nav的vc也是一样的结果。。。

是我哪里做错了嘛,有大神遇到这样的问题没? 谢谢

PHP中文网PHP中文网2741 days ago394

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 17:52:51

    The answer above should be clearer. You should not set the BarButton and title on the UINavigationController, but on the UIViewController it manages.

    This is reflected in your code: you should set it on the cityList UIViewController, not the cityListNav UINavigationController.

    reply
    0
  • 迷茫

    迷茫2017-04-17 17:52:51

    is cityList.title not cityListNav.title

    reply
    0
  • Cancelreply