如果使用popViewController

时间:2017-12-20 08:05:42

标签: ios objective-c uinavigationbar

我对NavigationBar上的UIBarButtonItem有疑问。

  1. 通过pusuViewController从FirstViewController传输到SeconderViewController。
  2. 使用NavigationBar左侧的返回按钮返回FirstViewController。
  3. [问题发生] NavigationBar右侧的[next]按钮的颜色是透明的。
  4. (你可以点击[next]按钮,但颜色是透明的)

    这个问题发生在iPhone8(iOS11.2.1(15C153)上,而不是iPhone6(iOS10.3.3(14G60))。

    enter image description here

    我的代码如下,

    AppDelegate.m

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
        self.window.backgroundColor = UIColor.blackColor;
    
        UIViewController *vc = [[FirstViewController alloc] init];
        UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
        self.window.rootViewController = nc;
        [self.window makeKeyAndVisible];
    
        return YES;
    }
    

    FirstViewContrtoller.m

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        self.navigationItem.title = @"First View";
        UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"next", nil)
                                                          style:UIBarButtonItemStylePlain
                                                         target:self
                                                         action:@selector(touchUpNextButton:)];
        self.navigationItem.rightBarButtonItem = nextButton;
    }
    
    - (void)touchUpNextButton:(id)sender
    {
        UIViewController *vc = [[SecondViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    

    SecondViewController.m

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    
        self.navigationItem.title = @"Second View";
    }
    

    如果你愿意为我提供一个好的解决方案,我将不胜感激。

    谢谢。

1 个答案:

答案 0 :(得分:1)

我认为这是iOS 11.2.1的漏洞 您可以通过以下解决方案临时修复:

UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"next", nil)
                                                      style:UIBarButtonItemStylePlain
                                                     target:self
                                                     action:@selector(touchUpNextButton:)];
[nextButton setTitleTextAttributes:@{NSForegroundColorAttributeName : [self.view tintColor], NSFontAttributeName:[UIFont systemFontOfSize:16.9f]} forState:UIControlStateNormal];

希望能帮到你。