修改UInavigationController损坏导航堆栈



我有一个标准的UINAvigation控制器,并按照正常的推动和弹出来推动我的屏幕。但是,我有一个屏幕,可以在按钮上的两个视图控制器之间切换,因此屏幕在顶部翻转另一个ViewController,反之亦然。您可以随意在它们之间切换。

现在,我希望返回按钮正常工作,因此我将顶视图控制器交换以实现以下操作:

-(IBAction)switchToSlowProductEntry:(id)sender
{   
    NSLog(@"Switching to slow product entry");
    // Replace the top view with the findProductView
    FindProductView *findProdView = [ProductViewInstances shared].findProductView;
    NSMutableArray *views = [self.navigationController.viewControllers mutableCopy];
    [views removeLastObject];
    [views addObject:findProdView];
    // if sender is nil then assume we started from the viewDidLoad so no animation
    if(sender)
    {
        [UIView transitionWithView:self.navigationController.view duration:0.3 options:UIViewAnimationOptionTransitionFlipFromRight animations:^
        {
            [self.navigationController setViewControllers:views animated:NO];
        }
        completion:^(BOOL finished) {}];
    }
    else
        [self.navigationController setViewControllers:views animated:NO];
    NSLog(@"Views: %@", views);
    [views release];
    [ProductViewInstances shared].lastScreen = SlowProductEntryView;
}
-(IBAction)switchToQuickProductEntry:(id)sender
{
    NSLog(@"Switching to fast product entry");
    // Replace the top view with the findProductView
    QuickOrderEntryView *quickProductView = [ProductViewInstances shared].quickProductView;
    NSMutableArray *views = [self.navigationController.viewControllers mutableCopy];
    [views removeLastObject];
    [views addObject:quickProductView];
    if(sender)
    {
        [UIView transitionWithView:self.navigationController.view duration:0.3 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^
         {
             [self.navigationController setViewControllers:views animated:NO];
         }
        completion:^(BOOL finished) {}];
    }
    else
        [self.navigationController setViewControllers:views animated:NO];
    NSLog(@"Views: %@", views);
    [views release];
    [ProductViewInstances shared].lastScreen = QuickProductEntryView;
}

我对另一个屏幕有类似的代码。我正在使用ProductViewInstances类来维护两个视图控制器,因为我不希望这些类在屏幕上保持阶段时卸载。

当您想从这些屏幕上向前移动时,我会按正常推动到新屏幕。它起作用了,我回顾了我添加的产品后就回去了。如果我向后退,我回到上面的屏幕上,一切似乎正常。但是,当我按下自定义的后背按钮(如果向后按下,我需要进行处理),我会遇到问题。

PopviewController什么都不做。这是管理自定义返回按钮的基类中的代码。

-(void) viewDidLoad
{   
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", nil)
                                                                              style:UIBarButtonItemStyleBordered
                                                                             target:self
                                                                             action:@selector(myCustomBack)] autorelease];
    if(![ProductViewInstances shared].findProductView)
    {
        [ProductViewInstances shared].findProductView = [[FindProductView alloc] init];
        [ProductViewInstances shared].findProductView.customer = self.customer;
    }
    if(![ProductViewInstances shared].quickProductView)
    {
        [ProductViewInstances shared].quickProductView = [[QuickOrderEntryView alloc] init];
        [ProductViewInstances shared].quickProductView.customer = self.customer;
    }
}

-(void) goBack
{
    if([[ProductViewInstances shared].quickProductView checkIfItemsPending])
    {
        // Pop up dialog
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Save Entries", nil)
            message:NSLocalizedString(@"Your entries will be lost", nil)
            delegate:self
            cancelButtonTitle:NSLocalizedString(@"Cancel", nil)
            otherButtonTitles:NSLocalizedString(@"Save", nil), nil];
        [alert show];
        [alert release];
    }
    else
    {
        // Remove rows from quick item entry screen
        [[ProductViewInstances shared].quickProductView removeRowsFromtable];
        if(didPressHome)
            [self popToSpringBoard:YES];
        else
            [self.navigationController popViewControllerAnimated:YES];
    }
}

因此,当我向后压时,我必须检查条目是否会丢失。流行板到跳板弹出几个屏幕,基本上调用以下内容:

NSArray *controllers = appDelegate.navigationController.viewControllers;
UIViewController *springboard = [controllers objectAtIndex:2];
[appDelegate.navigationController popToViewController:springboard animated:animated];

但是,popviewController动画呼叫什么都没做...就像从未发生过一样。

Donie

@selector(myCustomBack) will not call goBack unless you left out some code.

相关内容

  • 没有找到相关文章

最新更新