Pergunta

I currently have 1 storyboard which contains 2 view controllers: ViewController and TableViewController. The ViewController is the login view, and the TableViewController is the page that displays results (results view).

Currently, I did not create a segue from the login view to the results view. Instead, on the login view, after a user presses the login button and is authenticated, I programmatically push to the results view as follows.

XYZResultsTableViewController* controller = [[XYZResultsTableViewController alloc]init];
UINavigationController *navController = self.navigationController;
[navController popViewControllerAnimated:NO];
[navController pushViewController:controller animated:YES];

Indeed, the results view shows, but there is a "< Back" button at the top left, which, if pressed, goes back to the login view.

So, my question are:

  • How do I get rid of the login view from the view stack? (so the back button on the results view does not show)
  • Is this "programmatic" way of navigating between views "bad"? Meaning, should I rely on the storyboard and segues instead? Should I navigate to a new storyboard (I've seen this question asked on SO, though I haven't visited it yet)?

I'm a newcomer, so any help is appreciated.

Foi útil?

Solução

If you don't want to use the navigation stack, you have to use presentViewController instead of pushViewController

 XYZResultsTableViewController* controller = [[XYZResultsTableViewController alloc]init];
[viewController1 presentViewController:controller animated:YES];//viewcontroller1 is current view controller

Never use the code below unless you want to have the navigationController stack in viewController you are showing

  /*XYZResultsTableViewController* controller = [[XYZResultsTableViewController alloc]init];
 UINavigationController *navController = self.navigationController;
 [navController popViewControllerAnimated:NO];
 [navController pushViewController:controller animated:YES];  */

for more information on this difference between presentViewController and UINavigationController?

http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top