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也是一样的结果。。。

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

阅读 3.6k
2 个回答

楼上的回答应该比较清楚了。你不应该在 UINavigationController 上设置 BarButton 和 title,而是在其管理的 UIViewController 上设置。

体现在你的代码里就是:你应该在 cityList 这个 UIViewController 上设置,而不是 cityListNav 这个 UINavigationController 上设置。

是 cityList.title 不是 cityListNav.title
图片描述

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题