导航栏中有时会出现隐藏后退按钮

时间:2013-12-05 12:31:28

标签: ios background uisplitviewcontroller

在我的应用程序中,我使用Split视图,隐藏在详细视图控制器中的后退按钮,我也在做一些后台操作。有时,当应用程序在执行后台操作后从后台到前台时,隐藏的后退按钮会出现在导航栏上。只有当我们在完成后台操作后才到达前景时才会发生这种情况,如果我们来到前台并且仍然正在进行后台操作,则不会出现这种情况。我不明白为什么隐藏的后退按钮有时会出现,即使我隐藏了它。如果我点击该按钮没有任何反应,但它仍然出现。请帮我解决这个问题。

在右侧面板的RootView中,我隐藏了这样的后退按钮

  - (void) viewWillAppear
  {
        self.navigationController.navigationItem.hidesBackButton = YES;
        self.navigationController.navigationItem.leftBarButtonItem = nil;
  }

在didEnterBackground中,使用计时器启动后台任务

        UIApplication* app = [UIApplication sharedApplication];

        backgroundTask = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:backgroundTask];
        backgroundTask = UIBackgroundTaskInvalid;
    }];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        NSTimer* t = [NSTimer scheduledTimerWithTimeInterval:INITIAL_BACKGROUND_TIME_LIMIT target:self  selector:@selector(pushPullServer) userInfo:nil repeats:NO];
        [[NSRunLoop currentRunLoop] addTimer:t forMode:NSDefaultRunLoopMode];
        [[NSRunLoop currentRunLoop] run];
    });

来自后台,来自appDidBecomeActive

  - (void) appDidBecomeActive
  {
        self.splitViewController.viewControllers = [NSArray arrayWithObjects:self.tabBar, detailNavigation, nil];
        self.splitViewController.delegate = self;
        self.window.rootViewController = self.splitViewController;
  }

1 个答案:

答案 0 :(得分:4)

在视图控制器转换期间设置hidesBackButton属性时似乎是个问题(viewWillAppear是该进程的一部分)。我在iOS6中没有注意到这个问题,所以我认为这与iOS7处理转换和渲染的方式有关。

我的解决方案是确保hidesBackButton在初始化时具有正确的状态。因此,您需要在- (id)init或其中的某些变体中设置属性值。

如果无法做到这一点,那么我能做的最好就是将状态设置为viewDidAppear而不是viewWillAppear,确保它是动画的,这样对用户来说就不会太刺耳了。

例如:

[self.navigationItem setHidesBackButton:YES animated:YES];