弹出另一个视图后,保持视图的状态返回

时间:2015-11-11 14:50:54

标签: ios uinavigationcontroller navigationcontroller

我有一个搜索视图控制器,当最初点按搜索栏时,它处于初始状态。搜索后,您在同一个控制器中,但现在列出结果。如果您点击任何行,您将进入一个完全不同的视图,但当您点击后退按钮时,您将进入初始搜索视图,而不是搜索结果。有没有办法保存搜索结果状态,以便我可以将用户返回到他们的搜索?

这是加载所选搜索结果的代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.editing)
    {
        return;
    }

    ResultViewController * vc = [self resultViewControllerForIndex: [self.dataController indexForIndexPath:indexPath]];
    vc.title = [self titleForDetailsView];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController: vc animated: YES];

    _selectedCouponGuid = vc.result.guid;
}

这些是我尝试将这种观点带回来的不同方式。

//- (UIViewController *)backViewController {
- (void)backViewController {

    // attempt 1 -- crash
//    [self.navigationController pushViewController:self.navigationController.parentViewController animated:NO];

    // attempt 2 -- back to store listing
//    [self.navigationController popViewControllerAnimated:NO];

    // attempt 3 -- doesn't do anything
//    return self.presentingViewController;

    // attempt 4 -- back to discover screen, reload initial search tableview
//    [self.navigationController popToRootViewControllerAnimated:YES];

    // attempt 5 -- doesn't do anything
//    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

    // attempt 6
    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:3] animated:YES];
}

以下是VC进入结果并点击所选结果视图中的后退按钮

选择行

List of VCs: (
    "<HomeViewController: 0x7fbc8ebb8200>",
    "<ExploreViewController: 0x7fbc8e883a00>",
    "<SearchViewController: 0x7fbc8c005000>",
    "<ResultViewController: 0x7fbc8c1e7400>"

回击

List of VCs: (
   "<HomeViewController: 0x7fa519279c00>",
   "<ExploreViewController: 0x7fa51b806600>",
   "<SearchViewController: 0x7fa51b882800>",
   "<ResultViewController: 0x7fa51b0fea00>"

加载方法

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.titleView = [[UIView alloc] init];


    [self putStandardNavBarButtons: NO];

    _tableView = [[FancyTableView alloc] initWithFrame: self.view.bounds style: UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.scrollIndicatorInsets = UIEdgeInsetsMake(20, 0, 0, 0);
    _tableView.backgroundColor = [Styling defaultBackgroundColor];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview: _tableView];

    _DetailsHeaderView = [[CouponDetailsHeaderView alloc] initWithFrame: CGRectMake(0, 0, self.view.width, 0)];
    _DetailsHeaderView.delegate = self;
    [self updateViewsForCoupon];


    _releaseToViewImageLabel = [[UILabel alloc] initWithFrame: CGRectZero];
    _releaseToViewImageLabel.backgroundColor = [UIColor clearColor];
    _releaseToViewImageLabel.textColor = [UIColor whiteColor];
    _releaseToViewImageLabel.font = [Styling semiBoldFontOfSize: 14.0f];
    _releaseToViewImageLabel.textAlignment = NSTextAlignmentCenter;
    _releaseToViewImageLabel.text = @"Release to view image";
    [self.view addSubview: _releaseToViewImageLabel];

    [self reloadDetails];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear: animated];

    [UIView animateWithDuration: 0.3 delay: 0 options: UIViewAnimationOptionBeginFromCurrentState animations:^{
        [self setNeedsStatusBarAppearanceUpdate];
    } completion:^(BOOL finished) {

    }];

    [ExternalAnalytics trackViewForCoupon:self.coupon];

    if (self.redeemOnAppear)
    {
        self.redeemOnAppear = NO;
        [self showRedeemScreen];
    }
}

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    [self.view fillSuperView];

    [_tableView fillSuperView];

    [_releaseToViewImageLabel fillWidthOfSuperView];
    _releaseToViewImageLabel.height = 30;
    [self updateReleaseLabelPosition];
}

0 个答案:

没有答案