ios - vc中present了一个带nav的vc,但是弹出的vc不能设置其nav的titile和baritem?
PHP中文网
PHP中文网 2017-04-17 17:50:51
0
2
384

如题,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中文网

认证高级PHP讲师

reply all(2)
Peter_Zhu

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.

迷茫

is cityList.title not cityListNav.title

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!