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

如题,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讲师

répondre à tous(2)
Peter_Zhu

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

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

迷茫

是 cityList.title 不是 cityListNav.title

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!