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.
Related
I am new in developing iOS apps. I am trying to develop a multiple views app. My doubt is how to manage a multiple views app with View Controller, I mean, I do not want to use Navigation Controller nor Tab Controller.
My idea is to show a first View to choose the language, and after this, I want to show some different profiles in a table view. When you choose the profile, you get into a menu where you have some different functionalities (Once in this menu, I might use Navigation Controller).
My problem is that I don't know how to manage these two first views. I don't know if I have to declare them in the appDelegate, or if I can do it nesting one to other, I mean, I do the first view, and when I pressed the button, I declare the new view. Once in the new view, when I pressed a row in the table view, I make the another view.
I know it is a little bit confusing, so I hope you could understand it quite well.
EDIT:
I want to clarify that I am not using storyboards. My main doubt is what to do with all de view controllers, Do I have to declare all of them in the appDelegate? or Can I declare each view in every controller?
If you are using storyboards, you can use Segue's to navigate between the views, so you would show your first view, then you could tie a button to the next view (by control dragging in storyboard). If you want to transition programmatically you can use the performSegueWithIdentifier method. You could use the same approach to get from your tableViewController to your next viewController by using the performSegueWithIdentifier method from within the tableViewController's didSelectRowAtIndexPath delegate method (i.e. when a user taps a cell).
That should get you started. Good luck!
EDIT:
You really should be using storyboards. It's the way to do things these days. If you refuse, then the best approach is to create a container view controller that manages your "children" view controllers. You can find information on doing this, as well as the methods needed to present/remove child view controllers here:
Custom Container View Controllers
You can use navigation controller with "hidden" property.
self.navController.navigationBarHidden = YES;
If you want to have two different views and transition between them, you will want to use UIViewControllers presented modally. Here is Apple's Guide to this.
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
I've got a UISearchBar in my view, and when the results button is pressed I'd like it to load in a new view. Is this possible without using a navigation controller?
I'm new to iPhone development so not entirely sure if moving between views is solely reliable on a navigation controller or not. From all the examples I've seen using pushViewController, it seems to look that way. Hoping I'm proven wrong.
UINavigationController provides the simplest way to manage a stack of view controllers, but it's not necessary by any means; you can move your views around, and add and remove them from the hierarchy, however you like. Can you elaborate on what you're trying to do, and why you want to avoid using a navigation controller?
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.
I have following code in my application.
[self.navigationController pushViewController:x animated:YES];
It will push a new view to the application.
I want to change the animation time for pushing.
What should I Do?
You can't use the built-in UINavigationController Animation to accomplish this. It isn't customizable.
You will instead have to create your own animation, like with a CATransition. Then you can configure all of the attributes.
The only problem will be the navigation bar. You will have to handle that as well.
Also you will have to get the navigation hierarchy correct. You may have to be creative to get this right.