简体   繁体   中英

How can i pop to a required view controller when i click on back on navigation bar in iPhone

In my application i have 6 different view controllers. 1. Home page 2. A table view 3. Details of table view elements, this is also a table view with 4 rows 4. 4,5,6 Edit / modification views of details (each row in details table can modified and reloaded)

When edit hte data of details view in 4,5,6 views the navigation is pushed to 2nd view details view.

when ever i clicked on back navigation in details it pop to the previous view which is modified recently. But i need to pop (pushed to left/back side but not pushed to right side )to the tableview1 so i created a leftnavigation item implemented action for this button.

UIBarButtonItem *backButton = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(backclick:)] autorelease];
    self.navigationItem.leftBarButtonItem = backButton;

In click acitio I used three different approaches

1.popToRootViewcontroller : it takes back to the home page. so ,didn't need it (X)
2.[self.navigationController pushViewController:abc animated:YES]; it pushes right/front (X)
3.present model view controller

all are working and takes to the table view but not in the correct direction ie not pop to the back just pusshes to front. so, I used popto viewcontoller.

4.popViewController (it is the correct process i guess) but it crashes and shows an error view soesnot exixst

-(IBAction)backclick:(id)sender
{
    ChronologyViewController *temp = [[ChronologyViewController alloc]initWithNibName:@"ChronologyViewController" bundle:nil];
        [self.navigationController popToViewController:temp animated:YES];
}
for (UIViewController *vc in [self.navigationController viewControllers]) {
    if ([vc isMemberOfClass:[yourViewController class]]) {
        NSLog(@"Inside if");
        [self.navigationController popToViewController:vc animated:YES];
        return;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM