Convert Xcode view-based app to navigation-based app? - iphone

Newbie question: is there an easy way to convert a view-based app to a navigation-based app? I have an existing app sample that was created as a view-based app, and need to be able to create additional viewcontrollers that can be nested. The app is currently using presentModalViewController calls and nibs to display windows. Trying to change these to pushViewController calls results in the views not being displayed. So I'm assuming it's because the pushViewController needs to use a Navigation view. Thanks in advance!

Since you're admittedly a newbie, I would take the approach of creating a new navigation-based project and copying over your .xib and .m/.h files.
If you want to do it the hard way :), you'll add a NavigationController object to your MainWindow.xib. Then add a UINavigationController member and outlet and property to your app delegate, and connect it in interface builder to the navigation controller. At the end of your application:didFinishLaunching: method in your app delegate, set the window's view to navigationController.view. Back in MainWindow.xib, set the root navigation item to the view controller that used to be displayed at launch.

In you applicationDidFinishLaunching:, create a UINavigationController and add its view to the view hierarchy, then save it off to an ivar.
This is exactly what the navigation-based template is doing. There is nothing special about a "view-based" or "navigation-based" app,.

Related

Admob- Adding new ViewController

I'm fairly new to xcode, but I'm having some trouble adding admob to my app.
I followed the instructions for Admob but the ads are not showing up.
I'm thinking I need to add the new view I created AdViewController to appsdelegate. Is there a code I should add for that?
BTW: I'm using a tabbar controller as the rootviewcontroller
You're going to need to create something akin to a singleton GADBannerView. My recommendation would be just to create a GADBannerView object that you pass around through different view controllers but constantly have the UITabBarController as your rootViewController.
There's an example that uses a UITabBar solution at http://code.google.com/p/google-mobile-dev/source/browse/AdCatalog/Classes/AdvancedLayoutUseCases/TabbedViewExample/?repo=adcatalog-ios.

How to launch a window.xib file in storyboard?

I'm new to Xcode and building my first App, I want to incorporate a Twitter feed, my project is done in Storyboard but the Twitter feed code is with .xib, is there a good way to launch the .xib in Storyboard?
There is no real need to launch the window.xib in the storyboard. Just instantiate your view controller that is the file owner of your twitter feed code programmatically and push into your navigation controller. It won't cause any problems. The storyboard is basically an extension to the way screens were managed before. You can have all you "scenes" in storyboard and programmatically push a view controller from outside the storyboard without any problems and navigate back again.
The UINavigationController is the key. It only cares that it got a UIViewController.

Replacing UINavigationController With A UIViewController in MainWindows.xib

I am a newbie to iPhone app development. I want to make a simple app using view-based template which will have a main menu (home screen) linking to different modules of the app. Modules will themselves be made up of either UINavigationController or UITabController.
First I just wanted to create and bug a module, so I took a NavigationController in MainWndows.xib(appDelegate) and stacked(linked) many ViewControllers to it.
Now I need to have main menu at start of app, where I have placed NavigationController. I am now confused what to do? I have got solution in my mind that place this NavigationController in new xib file and a mainMenuViewController in MainWindow.xib file and access navigation module as a modal. So my Question is that if my approach is right? How will I access this modal controller to push viewcontrollers onto it? Or is there other alternate for what I want..?
I hope my Question is clear...
Any suggestion or link is appreciable.
I have got a better idea in my mind. I am going to stick with NavigationController in MainWindows.xib. I will push Main Menu as Root view Controller with both its navigation bar and toolbar hidden. Depending upon the button tapped, I will further push appropriate View Controllers on NavigationController.

XCode 4.1 - Multiple view within a XIB

I have created an application successfully and given it a TabBar view controller that is working as i had hoped, but have run into a glitch.
On each xib i load from the tabBar I need to create sub-views that will perform tasks as this interacts with a database (or .. will). I have created my first page and the buttons that will navigate to the views within the XIB, but do not yet nkow how to navigate between views within the XIB itself.
would it be better to have seperate XIB's that load when the buttons are hit?
OR
should i create views within the XIB's for each category and switch between them?
I am still learning and have had some confusion regarding navigation as I already have the TabBar controlling the root of the application. I have been looking for tutorials, but they all seem to start at either navigation controller as the root, TabBar as the root, and nothing like I need for option 1 above.
I can add details of the app if needed, but am looking for guidance for now.
Thank you,
Silver Tiger
To navigate between views the best way is to use a navigation controller pushing/popping separate view controllers, loaded from separate nibs. UINavigationController is a subclass of UIViewController, so you can perfectly put a navigation controller for each tab. You can also use story-boarding in the new xcode 4.2, but I recommend getting comfortable with this before doing so.

Iphone using mainwindow.xib confusion

In a navigation based application, when I want to create and use other uiviews and uitableviews I need to create their controller and views. in an example I saw that I can simply create a new controller with .xib file, design it, and just call that xib file from my navigationcontroller.
In another example, some stuff was going on also in the mainwindow.xib and some new controllers and navigation items were added from the mainwindow.xib.
What is the difference between these methods? when and why I should need to open and edit the mainwindow.xib file to add a controller?
The mainwindow.xib is your UIWindow component which you can see as a representation of your iphone screen, it will always be there no matter what. In your examples when you are showing your view controller dirrctly that is because the controller is already a subview of your UIWindow which is the mainwindow.xib in the Interface Builder.
There really is no difference between the 2 methods, in the first one you are adding your controller as a subview progrmatically using:
[window addsubview:mynavcontroller]
And in the second one youbare doing it thru interface builder, you may use whichever method you feel more comfortable with.
You do not really need a controller to show a view, however they can be handy if you want to do any extra stuff such as rotating your view or loading certain data when the view is loading. That being said you could add your view as a subview of your window and it would still work.