iOS not sure how to solve navigation design in my app - ios

My app inits with a navigation controller that opens up a table view.
If I then click on the menu icon in the header a modal segue gets fired and a login screen shows up. If you then login another modal segue gets fired and you end up on the account screen.
What I now want to do is to remove all other underlying VC's and make the account VC the first VC in the navigation stack. Is that possible?

Yes it's possible with setViewControllers:animated:, you can even make the transition animatable:
ViewController *viewController = [[ViewController alloc] init];
[navigationController setViewControllers:#[viewController] animated:YES];

Related

Can I start my iOS app on the 2nd View of My Storyboard and use the Unwind Segue?

I have two views in my Xcode Storyboard:
Login Screen -> UITableView
Is it possible to launch my app so that the UITableView is the first screen to display, and have an unwind segue that will take the user back to the Login Screen?
I am currently able to set the self.window.rootViewController in the App Delegate to set the first screen, but none of the unwind segues work.
Here's How I Got it to Work
I had to make sure my Login Screen had a Navigation Controller, then in the .m file for the Login Screen I used this code:
SecondViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"SecondViewControllerStoryboardId"];
[self.navigationController pushViewController:vc animated:NO];
Instead of explicitly setting your second view as rootViewController, just push it from your first view in its viewDidload method and then try unwind segues it will work.

Dismissing a modal view and pushing to a uinavigation controller through delegation [duplicate]

I have a tab view controller with a navigation controller. In the first tab item I click on a button in a view that pops up a view with animated: YES.
Then when that view is done I hit another button that dismisses it. Like:
[self dismissViewControllerAnimated:NO completion:^{
ProfilesViewController *profile = [[ProfilesViewController alloc] init];
[self.navigationController pushViewController:profile animated:YES];
//SHOW YOUR NEW VIEW CONTROLLER HERE!
}];
But everytime this code runs, it dismisses the view, DOES NOT push the profiles controller, and shows the view from the first tab bar item.
How do I push the ProfilesViewController to the screen with a Back arrow?
If you are using dismissViewControllerAnimated to dismiss that means that the VC is presented modally. As such, it doesn't have a navigation controller (so self.navigationController is nil) and thus it can't push anything into the navigation controller.
You should really add a property to the controller which is a delegate or a completion block which can be used to push the controller from another controller (the one that presents it) to dismiss and push the controller.
A second option is to pass the navigation controller, it's a similar amount of code to using a block but not so good.
A crappy option is to use the parentViewController to find the appropriate navigation controller, but that sucks for many reasons.

Login View Being Called Modally over TabBarController and works until I get to Navigation Screens

My app was working great and then client asked to put a login screen on.
I have a TabBarController with 4 tabs and I assign it the window as such in my app delegate.
[self.window addSubview:self.tabBarController.view];
Next, I had to put a login screen (view Controller) so I did it and called it like this
[self.tabBarController presentModalViewController:passwordController animated:NO];
and then dismiss it when the login is correct.
Now, when I put the app in the background each time I get my login screen (YEAH) with the exception of one. One of my tab's calls a navigation controller (well MasterViewController here is actually a view controller) and I call it like this
MasterViewController *masterViewController = [[MasterViewController alloc] init];
//TRYING TO GET IT TO STAY WITH TAB CONTROLLER
UINavigationController *navController = [[[UINavigationController alloc]initWithRootViewController:masterViewController] autorelease];
[self presentModalViewController:navController animated:YES];
and dismiss it when I need to. From there I am doing a bunch of core data stuff and I wanted my tab bar to disappear as I wanted the user to add/edit order in the correct order and not jump around to another place in the app using the tab bar (and then data being out of sync).
When I need to "drill down" to the next level I use
[self.navigationController pushViewController:eventController animated:YES]; and pop when I need to dismiss it.
So my question is this...I want the login screen to be presented on top whenever I return from the background on all screens.
I am sure the problem is the creation of the NavigationViewController not being part of that tabBarController
I did not include more code because it's all core data stuff or view controllers and all works well.
I am sure I am doing something terribly wrong and just don't understand (and I've built the entire app using advice on here so perhaps I followed bad advice).
I solved the problem like this..I created a navigation controller for each of the tabs that needed to "drill down" and had those navigation controllers initialized using the tabbarcontroller. Then in the app delegate when the appfinishedLaunching I called the security controller and it works everywhere. Just wanted to post for those who might be interested.

presentModalViewController on TabBarController App - blank screen after dismissModalViewController

i am using a tabbarcontroller in my app and also want to use a loginview.
I have an LoginController which handles the loginprocedure.
I am presenting the loginView modally.
[self.tabbarcontroller presentModalViewController:loginView animated:NO];
And on other point i am dismissing it(after login is successfull):
[self dismissModalViewControllerAnimated:YES];
After dismiss i have just a blank screen. Thats the blank window in my MainWindow.xib, i have checked it with a testlabel.
Throubles with that. No ideas how to solve this issue.
Two things:
The self.tabbarcontroller should not be instantiating the modal view. It should be the initial view controller that the tabbar controller controls. In the initialization of that view controller, you check for a login session and present the login VC.
Make sure you are dismissing that modal VC you created in the method that presented it. You should have a delegate method for your Login VC (something like loginFinished) that is handled in the VC that presented it.

TableViewCell disappears when push UINavigationController in UITabBarController's More tableview

I add 6 navigation controllers to UITabBarController's viewControllers. As normal, a More tab is created to list the last two. The problem is: after I select a table cell in the More table view, that cell's content fade out and disappear before the view controller push in. And then, after I back to the More table view by click the Back button, that cell's content show again. I guess the reason is More table view in its own navigation controller, and it push another navigation controller (created by me). I don't want to remove my navigation controller because I want to allow user rearrange tabs using the UITabBarController's Edit function. Can anyone suggest what I should do?
Create instances of your 6 navigation controllers in AppDelegate and retain them. And release in dealloc method
Just had the same problem. In my case I accidentally assigned the tabBarItem to the VC inside the navigation controller. When I instead initialized the tabBarItem on the navigation controller, the flickering / disappearing stopped.
MyViewController* viewController = [[MyViewController alloc] init];
UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewController release];
// this has to be navigation.tabBarItem (not viewController.tabBarItem)
[navigation.tabBarItem initWithTitle:#"Title" image:[UIImage imageNamed:#"fancy.png"]
tag:42];
Initializing the tabBarItem on the viewController still showed the icon which made it harder to discover. I'm also not very sure (actually I think it's bad) about the way I initialize the tabBarItem (without alloc). But I had troubles with disappearing icons etc and hey, it works ;-)

Resources