I have a search view controller that when initially tapping into the search bar is in it's initial state. After you search you are in the same controller but now listing the results. If you click through any of the rows you are brought to a totally different view but when you tap the back button you are brought to the initial search view, not the search results. Is there a way to save that search result state so that I can return users to their search?
This is the code for loading the selected search results
- (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;
}
These are the different ways I have tried to bring that view back.
//- (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];
}
And here are the VCs going into the result and tapping the back button out of the selected result view
Selecting row
List of VCs: (
"<HomeViewController: 0x7fbc8ebb8200>",
"<ExploreViewController: 0x7fbc8e883a00>",
"<SearchViewController: 0x7fbc8c005000>",
"<ResultViewController: 0x7fbc8c1e7400>"
Tapping Back
List of VCs: (
"<HomeViewController: 0x7fa519279c00>",
"<ExploreViewController: 0x7fa51b806600>",
"<SearchViewController: 0x7fa51b882800>",
"<ResultViewController: 0x7fa51b0fea00>"
Loading methods
- (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];
}