首頁  >  問答  >  主體

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 天前395

全部回覆(2)我來回復

  • 天蓬老师

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

    樓上的回答應該比較清楚了。你不應該在 UINavigationController 上設定 BarButton 和 title,而是在其管理的 UIViewController 上設定。

    體現在你的程式碼裡是:你應該在 cityList 這個 UIViewController 上設置,而不是 cityListNav 這個 UINavigationController 上設置。

    回覆
    0
  • 迷茫

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

    是 cityList.title 不是 cityListNav.title

    回覆
    0
  • 取消回覆