Cover UITableViewController view with contents of another nib - iphone

I have a UITableViewController that I need to cover with another nib in some situations
Whats a good way to do this?

You might want to check out the class UINavigationController. It helps you manage a stack of view controllers, with only the top one visible.

Depending on what you're attempting to do, you could use presentModalViewController:animated: to slide up a new view and cover your table. Then there is William's solution which would be to create a UINavigationController which will enable you to push and pop views into a stack.

Related

Objective - C How to manage multiple views with View Controller iphone

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.

Best practice to add an Application wide Header View in iOS

Let's say my main view controller will be a tab bar with misc sub view controllers (i.e the first will be navigation controller, the second will a subclass of uiviewcontroller, etc)
Now I want to add a static header view (will contain at least a logo uiimageview like websites)
so what is the best practice to achieve this?
EDIT: As Mark Adams explains in the comments, below, this is not a good strategy. I'll leave it as an note on what not to do.
"Best practice" is a dicey term, but what immediately comes to mind for me is to make your UITabBarController the root and only view controller of a parent UINavigationController. Then you can put whatever logo UIImageView you like in the navigation bar.
If you're not going for a UINavigationBar style, then I would recommend subclassing UIView and creating your custom view and using a simple implementation and offset value to add it to each of your UIViewControllers. Its a hassle, but it avoids having to throw on unnecessary UINavigationControllers to your project.
As for best practice, you should alway keep the UITabBarController as the root of your window, rather than having a UINavigationController with a UITabBarController as a root.
Also, I do appreciate the other poster's name.

Storyboard done, Do I need to create .h and .m View Controller file for each View created?

I have created Storyboard with several views calling each other, now I need to create the code
I notice that XCode didn't created .h and .m controller files for each View from storyboard.
Should I create them manually?
Should I keep only one controller? (or few depending of separation of concerns on MVC)
Is there a pattern for developing this?
thanks
The usual approach is one view controller pr. screen full of content. You can imagine having one view controller for a tableview, with any sort of content, and then another view controller that presents that content in a new screen full of content if a row is pressed.
Normally when you have subviews inside of your view controllers, you wire them up in interfacebuilder. Then for instance if you want to populate a view that has a uiimageview and a uiactivityindicatorview inside it, you can control their behavior and how their populated from the view controllers code. You could also if you want something very generic and you feel that one view will probably take up a lot of code in your view controller, create a uiview subclass for it, and then set the class in interface builder.
Did this help? Please let me know if you need more clarification.
It's entirely up to you whether you have a ViewController for each view. If you have many views I would recommend it. Even if you have 2 or 3 views you probably still should. Things can get really confusing when each view has a different task but all have similar IBOutlets.
TLDR; Personally, I would say it was good practice to have a ViewController for each view if each view has a separate task.

Having more than one NavigationControllers in one application in iPhone?

I want to use TabBar and wnat to also have more than one views.
But then is it possible to have one navigationController for each views?
I want keep track of views in each of them, and ofcourse it should display different navigationBar and views when I tab a new Tabbar item.
Is that possible? I could give it a try but I don't want to waste time. So if it's possiblt, I'm going to start to work.
Thanks to any advice.
Short answer, yes, it's possible. :)
Longer answer: For each of the UIViewControllers, you would instantiate a UINavigationController and set the UIViewController as the root view using initWithRootViewController:. You would then pass these UINavigationControllers into the UITabBarController by setting the viewControllers property.

Multiple views and controllers in UITabBarController

I'm trying to add multiple views inside a UITabBarController. Currently my object hierarchy looks like this: UITabBarController -> UIViewController* -> UIView*. As a more concrete example, the first view controller for my UITabBarController is a UIViewController, and that has three subviews, which are controlled by a UISegmentedControl. Depending on what segment is selected, I push the corresponding view to the front.
I understand that I can use a UINavigationController to manage my three views; however, the data I wish to present is not really hierarchical.
Are there examples of container controllers other than UITabBarController or UINavigationController that I can use for this case? Or is there another approach I should use (I'm currently managing views manually).
Thanks!
Custom view controllers are covered in the View Controller Programming Guide.
If you wanted to change your layout to use the UINavigationController you could remove the segmented control view and have the first view be a table view inside a nav controller. The table would have the three options the segmented control had and tapping on them would push the view associated with that option. This way you've created a hierarchical view layout rather than using the segmented control, which is typically used to toggle functionality rather than control views.
If you choose to do this, these two guide sections would be a good place to start.
There's not really any supporting framework for this - usually you have to manage switching out views in a switched container view yourself.
One approach I have taken in the past is to maintain an array of ViewControllers for each switching view, and take the viewController.view to add as a subview of your switched container view. Then I write code around the switching of the view controllers to call viewWillAppear and viewWillDisappear on the contained view controllers as they are swapped in and out, that makes things much simpler since you can treat them totally separately.
You can write that class kind of generically and then re-use it.