IOS Switch to another view

I have a navigation based application. The root view is a list of items. In this root view, you can click on a table cell for a detailed view of the element. Or you can go to the form to create a new item using the "Add" button in the navigation panel.

My question is, how can I switch from a form view to a detailed view after creating a new object?

I don’t want to click the detailed view at the top of the form, because I want the root table view to be what the user sees after clicking the nav back button, forming a detailed view.

I have tried the following. It appears in the root view perfectly, but after that the detailed view does not open.

[context save:&error];

[self.navigationController popToRootViewControllerAnimated:NO];

// display detail view
GoalDetailViewController *detailViewController = [[GoalDetailViewController alloc] initWithNibName:@"GoalDetailViewController" bundle:nil];

// Pass the selected object to the new view controller.
detailViewController.goal = goal;

[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];

Any help and guidance would be much appreciated :)

Hooray!

+3
2

, , .

[self presentModalViewController:modalViewController animated:YES];

, (. ). , , , , "" .

+3

, , :

// Get the current view controller stack.
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];

// Instantiate your new detail view controller
GoalDetailViewController *detailViewController = [[GoalDetailViewController alloc] initWithNibName:@"GoalDetailViewController" bundle:nil];
detailViewController.goal = goal;

// Remove the topmost view controller from the stack
[viewControllers removeLastObject];
// Replace it with the new detail view controller
[viewControllers addObject:detailViewController];

// Change the view controller stack
[self.navigationController setViewControllers:viewControllers animated:YES];

// Clean up
[detailViewController release];

, , .

+1

Source: https://habr.com/ru/post/1768354/


All Articles