I am currently developing an App based on a Navigation Controller. However, when the user logs out, I'd like to go to the initial screen and destroy all of the other views that were stacked. What is the best way to do that?
EDIT:
I've tried doing what both answers suggested but I got a nil navigationViewController. So I'll add another detail that I thought was not useful before. Actually I am trying to perform this operation from a TabViewController that is embedded in a NavigationController. I apologize if that changes anything.
[self.navigationController popToRootViewControllerAnimated:YES];
Send a popToRootViewControllerAnimated message to the navigation controller
Related
Being new to iPhone development I am really struggling with this concept. I have built an App which is not quite running the way that it should. I have a TabBar app. The secondViewController is essentially a form which I use to collect information about daily exercise. I have embedded this secondViewController into a Navigation controller so that I can push to a datePicker view and return with the date. I also push to a pickerView for exercise type and return with data. At least this is the intended process. I use the prepareForSegue to push the picker views and return to the secondViewController carrying data between them with each segue.
What I find is happening is that instead of pushing to the picker views and returning to the secondViewController my app seems to progress in a linear fashion. To be more precise it seems to push to the date picker, then push to a new 'instance' of the secondViewController, then push to pickerView, and then to another new instance of secondViewController. This means that when my users eventually touch the save button, they have to use the back button in the navBar to get back to the original secondViewController.
[Have an image to add but can't post it as I have reputation under 10 :-( ]
I have read Apple's documentation on managing the stack and hierarchy, but I just seem to have confused myself more than anything else. I have also searched for answers and tutorials, but I am either missing something or there is no clear explanation of how this is supposed to work that I can find. Can anyone tell me how to push to a pickerView and then return, or at least to return programmatically to the original secondViewController when the save button is finally touched?
To go Back in hierarchy in UINavigation Controller you can use
[self.navigationController popViewControllerAnimated:YES];
I am trying to create multiple views in my view-based iPhone app in Xcode 4. I have followed many tutorials and read many articles but none of them have worked. I figured out that they require a Navigation Controller. How can I create 2 views that are switched with a button without a Navigation Controller?
Thanks!
I would use presentModalViewController. There are a ton of youtube videos on how to switch views, some of them don't have presentModalViewController so you have to watch the video to see if they write presentModalViewController in their code. I always use presentModalViewController.
you can create one additional view and keep it as a retained variable in your controller and on demand, you can do
[self.view addSubview:secondView];
//or - to remove second view and show first view
[secondView removeFromSuperView];
Why not use a UINavigationController but disable the navigation bar?
It's the easiest way to do it. And it will avoid many issues that can come about with incorrect view controller programming. Your users will never know the difference - there are no visual clues that you've done it that way.
I'm developing an iphone apllication that stores some data into a database. That is working fine. But now i have a problem when i want to show the data. Because to show the data i need to design another view. But i'm facing problem when i try to add another view.Is it possible to have multiple view in a view-based application,cause my application is a view-based application? If yes then how to do that? Please help me
Thanks in advance
Joy
yes. In principle you create your new view [alloc/ init], then display it.
Normally you would display it by pushing it onto the navigation controller stack.
[self.navigationController pushViewController:newViewController animated:YES];
If you don't have a navigation controller, you either need to create one (your best bet might be to use xcode to make a navigation based application and take a look at how its put together).
If you just want to simply display a second view controller, then you can display that as a modal view controller: alloc/init your second view controller then display it with
[self presetModalViewController:newViewContoller animated:YES];
Finally you could do a front view/ flipside view. Take a look at the utility application template in xcode.
Yes it is possible to use multiple views. You can manually add them to the window by using addSubView.
You can also use a view controller like a UINavigationController or a UITabBarController.
It depends on how you want to display the views and how the user can switch between them.
could anyone help me with the next question. I am working on an app with the navigation similar to Notes app has. The problem I faced i how to implement navigation within one level and keep root view as the previous screen. So the scenario I need to achieve:
1. Drill down from the top level list to the detailed view.
2. From this detailed view navigate to the detailed view of the next/previous item.
3. Back button should lead to the root view.
I've tried several approaches and no-one worked fine for me. The most right solution from my point of view is to create a middle controller between the root and detailed controllers to handle this next/prev redirects. But the main problem here is that switching from one detailed view to another the navigation pane stays the same, so it's not involved in the animation, whether Notes app work right in this case.
Could you point me how it' better to arrange controllers interaction in this case?
Thanks in advance. Sorry for quite big post, was trying to be as informative as possible.
Best regards,
Roman
I think the best implementation is this way:
Say you have a Note class where the data is stored.
You could have two view controllers, one with the list of notes and one with the details.
Both of these can be added to a navigation controller.
Then, when you want to switch to the next note, you retrieve that object somehow and assign it to your detail controller with a -setNote: call. That method will be responsible for changing what the outlets are displaying.
I've resolved this question - it's enough to pop current view and push new one, created for the next object in the list. The only think to remember is to save the reference to the navigation controller before the pop call, because after it self.navigationController becomes nil.
Yeah, it's misbehaving badly. Jongsma's reply is the best. In case you wanted to re-create controllers, I've found this to work:
[parent performSelectorOnMainThread:#selector(showMyItem:)
withObject:myNextItem
waitUntilDone:NO];
[self.navigationController popViewControllerAnimated:NO];
performSelectorOnMainThread delays execution of the method until the next run of the main loop, and by then the previous controller is removed already and navigation controller is in a stable state.
In my application i have used the UiViewController and able to push the other view using the PushViewController.
But, whenever i am using the presentModalViewController at that time i am not able to get whole functionality of the BackButton click event on the view which is working fine for the pushviewController.By using the debug i am able to reach at the function,but not able to execute the whole piece of code into that function.i have used below code.
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController dismissModalViewControllerAnimated:YES];
But not able to get back to the push page.None of the lines effect is seen on the application.
Can any body give me any suggestion if i have done something unusual from transferring from PushviewController to presentModalViewController?
i just want the presentModalViewController in my application for some effect as horizontal or vertical.But,i am not able to see any effect of the event on that view.i am able to see the horizontal and vertical effect.
please guide me with proper resolution or any other solution which would be appreciated.
Thanks,
Mishal Shah.
I don't think the navigationController property is set inside of your ModalViewController. So saying self.navigationController wouldn't work inside of your Modal View Controller. That is, if that's even where you put it, I don't really understand from the way you formatted your question.
If you want more help post some more code/format it better/start accepting more answers to your questions.
I think accepted practice is to dismiss the modal view controller from the view control in which you presented it. Use a notification to send a message back to the presenting controller and dismiss it there.
I think that is what you were asking, the question is somewhat unclear.