iphone - transforming a view-based project - iphone

sorry bothering you guys with this silly question, but I am a kind of noob in iphone development. What I need to do is this. I have a project developed by a friend of mine, that is view-based. He created it based on the original apple template on Xcode.
After banging my head on the wall, I realized that I need to transform this project from view based to UINavigation based project. What I mean is: his project has one view controller and one delegate. When it runs, the delegate calls the view controler and the equivalent view loads.
What I need is to insert a UINavigationController before the ViewController, because I am planning to have a second ViewController managed by this UINavigationController, so I can do slide transitions between them and things like that.
My question is: I imagine this is not a complex operation if you want where to change. Which changes and where should I do them, in order to add a UINavigationController before the viewController? I imagine this will change the hierarchy to:
Delegate > UINavigagionController > ViewController
Remember that this project was based on the Xcode View-based template, so I will probably have to change stuff on Interface Builder.
Thanks.

In IB, add a UINavigationController to your MainWindow.xib.
Drag the existing view controller onto the nav controller icon to make it the nav controller's root controller.
In your code, add a property to your application delegate for the navigation controller. Mark it as IBOutlet.
In IB, connect the navigation controller object to the navigation controller outlet in your app delegate.
In your code, in -application:didFinishLaunchingWithOptions:, change the references to your original view controller to the new navigation controller property.

Related

Creating a custom view to replace UINavigationBar

I've had a lot of experience customizing UINavigationBars and find it is a royal pain in the a** to get it to do what I want without a lot of effort. So I've written my own custom UIView that behaves just like a UINavigationBar and is fully and easily customizable. However, I am having a problem, when the Navigation controller pushes a new controller onto the stack, my custom view stops receiving touch events.
To make this more clear, my app loads and displays a view controller, in the viewDidLoad method, I create and add my custom nav bar to the controller's view. A navigation controller is created programmatically and a view controller is pushed to it. At this point my custom view is on top and receiving touch events. When I push another view controller to the navigation controller's stack, my custom view is still on top and visible, but not receiving events.
So my question is how to I get my custom nav bar back into the responder chain?
Thanks for your help!
If you don't have to support iOS < 5.0 you should try to add the UINavigationBar using UINavigationController's - (instancetype)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass method instead of doing it manually.

Changing UIViewController tab bar view to UINavigationController in Xcode 4

I am trying to modify a newly placed UITabBarItem item from a UIViewController to a UINavigationController in XCode 4.
Here is a screenshot of a new view controller called "Near Me" and existing view controllers.
Notice how the new one is a UIViewController, I need this changed to a UINavigationController.
Something as simple as this was easily done in Xcode 3.2 and now that Apple has introduced Xcode 4 - it is just horribly difficult to re-learn this new IDE.
You shouldn't modify a UIViewController to be a UINavigationController. Even though a UINavigationController is a subclass of UIViewController, its job is to manage other View Controllers, not Views.
In IB you should create a UINavigationController and then set the existing UIViewController as the root controller of the new UINavigationController.
You can change it in the menu on the right hand side. Just change the class. I hope this is what you are asking for.
First you create window based application an in that MainWindow.xib file put tabBar Controller. Then delete that two UIView controller and add navigation controller under tabBar Controller. You can see below in screen shot.

iPhone Obj C - 2nd XIB How to configure a Nav Controller and View Controller

Still learning Obj-C slowly... forgive the dumb questions...
On my 1st XIB I have the App Delegate, Nav Controller and several view controllers. Along with that I have several buttons that calls a 2nd or 3rd or subsequent XIB.
The subsequent XIBS all have buttons which display views.
So on the 2nd+ XIB I have configured it in the .h as an UIViewController however I am guessing I need to make it something else like the primary .h is an AppDelgate.
So right now the XIB wants the view set, but I don't want it to go to a view, I want it to go to the view controller... I think??
Maybe I am still going about this all wrong. I need the primary menu to call the next menu (2nd XIB) which in turn calls various views. In my Java Android app I have about 70 classes, and guess and about 45 views so I am guessing again that I do in fact need the multiple XIBS.
So the question is how do I set up the additional XIBs? Are they AppDelegates or what?
Does that change the way I call the 2nd XIB?
The XIBs or the UIViews (or it's subclasses) are just the facial make up.
For the actually programming part, you deal directly among the "controllers" classes for these views.
View controllers that you make can have an XIB attached to them. But the behavior of how and when the view is shown or hidden, is all handled by the view controller itself.
So to come to the point, if you want to have a navigation bar on the top of you app (assuming that it's a simple app wanting to show many views with a navigation bar):
Create a UINavigationController instance in your applicationDidFinishLaunching: method in the app delegate:
// Assuming that mainViewController is the first controller + view for your app.
navigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
[window addSubview:navigationController.view];
This will automatically add a navigation bar to your views. You don't need to add them manually in XIB or anywhere else. Now how you draw/implement mainViewController, is up to you.
When you want to show another view from within mainViewController, you should call:
AnotherViewController *anotherViewController = [[[AnotherViewController alloc] init] autorelease];
[self.navigationController pushViewController:anotherViewController animated:YES];
This will "push" your new view (from anotherViewController instance) into your navigation structure, which will automatically add a back button on the top.
Hope this helps clear the scene of how it works, a bit.
If you have doubts, comment about it. Have a great day!

Problem Adding UITabbar to Existing UITableView - iPhone SDK

Wonder if anyone can help me with this problem. I have created a Window based application. I have then added a Navigation Controller to the Window (via Interface builder) and subclassesd UITableViewController and used the table delegates in this class to draw my root view table. This all works fine.
I am now trying to add a tab bar to the view. I have done this by dragging a UITabbar in Interface Builder onto the Main Window.
The problem is that when I launch the app, it looks like the table is now being drawn over the top of the UITabbar which therefore makes the UITabbar unaccessible.
Can anyone help me ?
Thanks in advance,
Martin
Have a look at View Controller Programming Guide for iOS : Tab Bar Controllers
If you want to add a tab bar to your application, it should be the main navigation base of your application. Navigation Controller can be part of each tab.
Create a tabBarController. Create navigation Controllers with appropriate View Controllers as its Root View Controller, add the Navigation Controllers into one array, set it to the viewControllers aray of tabBarController object and add the tabBarController.view to your window.
Have a look at this thread, both coding & IB approach has been explained here.
The better and easier approach would be to create UITabbar based application with navigation and add UITableView into that.

Creating an overlay view ontop of EAGLView

I am creating a game using OpenGLES.
Game consists of a view controller and the EAGLView.
I have created another view controller that I want to handle the extra view that go ontop of the EAGLView so things like menu and options.
I have a call from the EAGLView view controller to the extra view controller that adds an IBOUTLET UIView to the appdelegates window however its not appearing. The methods being called but no view is being added.
Probably a really easy and stupid question but I cant work it out.
Thanks for any help in advance
Ok I have done it a different way.
I use a view Controller called GameViewController to load up and i add its subview to the window in the appDelegates applicationDidFinishLaunching method
Then i call a method to add another view controllers view (my open gl view) to the subview. This means I can then put other views over the top.
I don't know why i didn't do this before to be honest
Thanks for your help
Can you be more specific with this sentence:
I have a call from the EAGLView view controller to the extra view controller that adds an IBOUTLET UIView to the appdelegates window however its not appearing.
One approach is to use navigation controller that could be initalized with EAGLView controller as root. So, you can push and pop in navigation controller another view controller that handles the game menus.
Another approach is to present menu as modal view controller. This can be invoked with presentModalViewController: in current EAGLView controller.