Window based application or Navigation based application - ios

i'm starting developing a new iPhone application, the interfaces that i will implement contains a lot of that shaft :
I have actually two question, what the suitable template to use? Window or Navigation based application?
Second question : in the Navigation Based Application, the first view that appears when i run the app is the one that contains a UITableView as below, can i replace it by an Image (UIImageView)?

Yes, Navigation based app is what you are looking for here. And yes, you can replace the UITableView with a UIImageView. I tend to start any project with a Window based project, and here's a quick way of doing it using window based project:
Create a window based project
Create you first view controller
Then in you application delegate, in the method applicationDidFinishLaunching, create a navigation controller, set it's root view controller to the view controller you created in the last step, and set the mac controller as the root view controller of the window. Here's a sample code:
FirstVC firstVC = [[FirstVC alloc] initWithNibName:#"FirstVC" bundle:#"nil"];
UINavigationConroller *navVC = [[UINavigationController alloc] initWithRootViewController:firstVC];
[[self window] setRootViewController:firstVC];
If you want to use a Navigation based project, then simply at the initWithRootViewController, remove the view controller set up by the template and set it to your own view controller.

Related

What sort of view controller approach is best for an iPhone iOS app using multiple window views?

I am interested in creating an app that starts with a menu which may possibly contain an options view, then steps from the menu view to a data-item selection view, then to a configuration view, and finally a result view that displays progress or changes. I want to have this process be repeatable like a loop, and have the user be able to jump backwards to a previous view if necessary. Jumping from view to view would of course be a user input / output with a button or something. FYI, I am using Xcode 5.1.1.
What would be the best approach to this? What kind of view controller is going to do the trick? I have heard a lot about navigation controllers, tables, etc.. but am having a hard time figuring out what to use in my case.
Below is a state-diagram similar to what I would like to do...
A UINavigationController should work great as your root view controller. It automatically includes a back button, and you can use the popToRootViewController method to return to the root of the navigation controller. You can set up a navigation controller as your root view controller from the applicationDidFinishLaunching method using this code.
MainMenuViewController *mainMenuViewController = [[MainMenuViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mainMenuViewController;
self.window.rootViewController = navController;
For more information take a look at apples UINavigationController programming guide https://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
Each of your other screens may use different types of view controllers depending on their specific needs. If you need to display a list of items, definitely look into a UITableView. Apple's documentation for a UITableViewController can be found here https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewController_Class/Reference/Reference.html

Getting ViewController from TabBarController Best Practices

I'm working on a car app.
I have a tabBar linked to different view controllers (CarInfoViewController is one of them).
I'm passing data to one of the view controller using the following way
CarInfoViewController *myCarInfoController = [self.tabBarController.viewControllers objectAtIndex:2];
[myCarInfoController setSearchParam:vin];
I want to know what is the difference between getting the view controller directly from the TabBar using objectAtIndex vs. doing the following :
CarInfoViewController *myCarInfoController = [[CarInfoViewController alloc] init];
[myCarInfoController setSearchParam:vin];
Both ways are working! I'm curious to see what is the best practice in such case.
I doubt that both work fine.
Unless, of course, when you create the view controllers programmatically anyway and it is the very myCarInfoController object that you created and add it to the tab bar controller later.
With your first statement you receive a controller from your tab bar. That may well be a controller which was created in Interface Builder or Storyboard Editor respecteively. Of this view controller you know that it is the one in tab no. 3 (index no. 2)
Your second statement allocated a brand new instance of your CarInfoViewController. Assuming that there is one already that was created before (in IB or so) and resides as 3rd controller in your tab bar controller, then you have two intances of the same class which are not related to each other. if you know pass any data to myCarInfoController (of variant 2) then nothing at all will happen in/to that very instance that is acutally used by the tab bar controller.

How to structure an app when using UINavigationController as the window's root view

I'm starting to learn iOS development and am attempting to use UINavigationController as my window's root view. All is working well but I need some advice on how to structure my app. I read the docs and some questions on here too.
Since the navigation controller is managing all my other content view controllers, then all of these view controllers need a way to send messages to the navigation controller. Right? So, I've thought about making a singleton navigation controller that any other view controller can call on to push new view controllers on it. Or, if each view controller has a reference to the navigation controller then they can push/pop easily as well. This is the part I'm not sure about.
Also, for having buttons and actions I have been setting the target as the navigation controller and from there it can handle it correctly and push or pop on it's own. I did subclass UINavigationController for this. And I have my view controllers as references in it. However I ran into an issue where my UITableViewController was handling a selection of a row and I need to push a new view controller on top, but how do I get the reference to the navigation controller?
I hope that makes sense, and any advice on how to structure this would be very appreciated.
Thanks!
I think you're overthinking this. View controllers have a navigationController property built in allowing you to reference the navigation controller. That being said, pushing to a new view controller from within a view controller that is embedded in a navigation controller is as easy as:
UIViewController *myNewViewController = [[UIViewController alloc] init];
[self.navigationController pushViewController:myNewViewController animated:YES];
According to your requirement you need to write like this :-
UIViewController *myNewViewController =
[[[UIViewController alloc]
initWithNibName:#"yourNibName"]
bundle:nil]];
[self.navigationController
pushViewController:myNewViewController
animated:YES];
This will push one controller on the bottom of the stack.

what type of view controller is this?

and how do you create it? - the popup one in the middle
I would lie to use something like this for my game (in the main menu).
There is no type for UIViewController. There are different ways how you can present UIViewController.
iPad support following three type:
Full Screen
Page Sheet
From Sheet
Your image is showing third one UIModalPresentationFormSheet.
You can Find detail of how to use this three type of presentation at following app guide:
Presenting View Controllers from Other View Controllers.
That's the link to the documentation.
Presenting View Controllers from Other View Controllers
A modal view controller is a controller that can be presented on top of another one.
To create it, for example, you can just call presentViewController:animated:completion: method of the current view controller, passing in the view controller you want to present.
Since the interface you have uploaded contains a navigation bar that contains a close bar button item, you can simply wrap the controller you want to present in a navigation controller.
YourViewController *yourViewController = [[YourViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:yourViewController];
[self presentViewController:navigationController animated:YES completion: nil];
Otherwise, you can create a plain controller and use a UIToolBar.
Hope that helps.
P.S. The close button will not be there for free. You need to add it ;)
I think it would be much better to use a third party library instead of implementing it. There are many libraries that offer similar functionality.
UAModalPanel
MTPopupWindow
KGModal
If you do not want to use the above libraries, you can use UIModalPresentationFormSheet explained by Apple in this document: Presenting View Controllers from Other View Controllers
Hope this helps!

Change RootViewController inside UISplitView

I'm developing a little example for iPad from a UISplitView XCode Template. It's formed by a root controller which is shown in the left of the window and a detail view which is shown in the right.
What I want to achieve is very simple (at least I think so) but I can't find in the documentation the way to do it.
I'd like to substitute the root controller (which appears fixed in the left) with a new controller (for example as response to a event launched when you push a button). I've tried this:
ColorPicker *controlador = [[ColorPicker alloc] initWithNibName:nil bundle:nil];
[self.rootViewController presentModalViewController:controlador animated:YES];
[controlador release];
What happens with that is that the new pushed controller fills the entire window, whereas what I want is that appears fixed at the left with the two columns format that were at the beginning.
You need to set the modalPresentationStyle to an appropriate value,
controlador.modalPresentationStyle = UIModalPresentationCurrentContext;
UIModalPresentationCurrentContext instructs the view controller to appear modally within the frame of the rootViewController.
Use pushViewController:animated instead may fix this. About ModalViewController, check document http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

Resources