Loading Tab Controller View in Window Based iPhone App - iphone

I am learning how to create apps with multiple views using the Window-based application template. I am trying to implement a tab bar but when my view loads, it is a blank. I realize it could be an issue between versions of iPhone SDK or Xcode. I am using the latest version of both (iOS 4.3 and Xcode 4.0).
My current code is as follows:
.h file:
#interface iBountyHunterAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *tabcontroller;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *tabcontroller;
.m file:
#synthesize window;
#synthesize tabcontroller;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:tabcontroller.view];
[window makeKeyAndVisible];
}
In the sample code I downloaded, this worked fine. I can't figure out where the problem is and any suggestions would be greatly appreciated.

Have you added any view controllers to the tab bar controller? The tab bar controller doesn't have any content of its own, other than the tab bar itself. You need to add your own view controllers using -setViewControllers:animated:.

So I think I figured it out. Due to the lack of the UIWindow *window in the ApplicationDelegate.h #interface:
I had to reference [self.window addSubview:tabcontroller.view]; in my application didFinishLaunching method,
rather than just [window addSubview:tabcontroller.view];
Thanks for the assistance.

Related

Xcode 4.2 - Property IBOutlet won't Snap to Storyboard View

I'm learning about iPad development from the book Head First iPhone & iPad Development (2nd Edition). I'm stuck in chapter 7, page 347. This is the chapter on taking the DrinkMixer iPhone app and turning it into a universal app for both the iPhone and the iPad.
We added a split view controller (UISplitViewController) and the coding behind it all goes well (no build errors). The one difference I'm doing is that I'm using storyboards. Up to this point it's been going well, but now the book says to add a split view property IBOutlet (code below) for the detail view controller (*splitViewDetailView) and hook that #property up to the detail view.
MasterViewController.h
#import <UIKit/UIKit.h>
#class DetailViewController;
#interface MasterViewController : UITableViewController {
NSMutableArray *drinks;
DetailViewController *splitViewDetailView;
}
#property (nonatomic, retain) NSMutableArray *drinks;
#property (nonatomic, retain) IBOutlet DetailViewController *splitViewDetailView;
#end
MasterViewController.m (top part)
#import "MasterViewController.h"
#import "DetailViewController.h"
#import "AddDrinkViewController.h"
#import "DrinkConstants.h"
#implementation MasterViewController
#synthesize drinks;
#synthesize splitViewDetailView;
The problem I'm having is that when I try to hook up the property to the detail view, it won't let me. The connection wire won't snap into the view. I've done many other IBOutlets and IBActions so far and it was easy to do. Anyone know what I'm doing wrong?
I've tried to search for a similar issues here on stack overflow and the web for the past 2 days and so far I've come up empty.
I found out that I was going about this the wrong way. The solution was simpler than I thought.
Link
Thank you Marcus Buffett. I'd vote you up but I don't have enough reputation points yet.

steps to add tabbarcontroller to AppDelegate using Interface Builder in XCode 4.2 Empty Application template

while I'm stuck at this question I cannot find the right steps to add a UITabBarController to the AppDelegate (not programatically) but by using interface builder for the "Empty Application" template, I tried to add a new empty xib file, then dropped uitabbarcontroller into it, but there is no way to link it (from IB) to AppDelegate !! i.e. when I move the blue line from tabbarcontroller object (in document outline) to File's Owner, interface builder shows only the "Delegate" option in the shown list so there is no IBOutlet option in there.
so, what are the exact steps for adding a tabbarcontroller and connect it to appDelegate using the interface builder way (for the Empty Application template, using XCode 4.2 and IOS 5 SDK) ?
step1: create new Empty Application template project.
... waiting for the next steps...
thanks so much in advance.
Step 1: create new Empty Application template project.
Step 2: add
#property (nonatomic, strong) IBOutlet UITabBarController *tabBarController;
#property (nonatomic, strong) IBOutlet UIWindow *window;
in your app delegate. (dont forget to synthesize these)
Step 3: change this line in your app delegate:
#interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>
Step 4: modify this method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:[self.tabBarController view]];
[self.window makeKeyAndVisible];
return YES;
}
Step 5: create a new empty xib. Drag a tab bar controller on to it as well as an empty object.
Set the empty object's class to AppDelegate. Set Files Owner to UIApplication.
Step 6: drag the 'delegate' property from your files owner on to your appdelegate class and drag the tab bar outlet from you appdelegate class to your tabbarcontroller
Step 7: Add a window and drag the 'window' connection from your appdelegate to the window.
Step 8: Dont forget to go into the project settings and set the main-base nib file to the new xib you created.
Thats it. Hope I didn't miss anything.
I don't understand what is the need to add a UITabBarController through the main window. With Xcode 4.2, Apple has made some changes in the default templates. It does not provide a MainWindow.xib in the Empty Application. That is why, if you open up the AppDelegate.h, you will see:
#property (strong, nonatomic) UIWindow *window;
It does not have an IBOutlet for the window as we used to see in previous Xcode versions.
What you want to achieve is a UITabBarController with Core Data support. You could add the tabBarController programatically, and still add CoreData support.
Here's what I had to do.
From your storyboard's Objects list (Controllers & Objects) in the Utilities panel, drag over a generic "Object" (yellow cube) to your Tab Bar Controller Scene page (I place the object under the "Exit" object).
Set the class of the object to your appDelegate. Now you should be able to link your Tab Bar Controller's delegate to your appDelegate object. You can also link the appDelegate to the Tab Bar Controller if you've created a property such as
#property (weak, nonatomic, readwrite) IBOutlet UITabBarController *tabs

How to add tabbar in cameraView of zbar sdk

I'm a newbie in iphone app developing, I just started learning two weeks ago due to the need of my final project.
So please forgive me if my question seems really stupid.
I've searched in forums and zbar documentation about how to customize the cameraView.
But I still didn't have a clear understanding about how to do it.
Now I'm trying to add tabbar into the cameraView, could anybody tell me how to do it?
I know that I need to use overlay and create my own view, adding the reader as a subview in it. Could anybody give me some direction more explicitly about how to reaise it?
Thanks in advance!!
You have to create your own custom UITabBarController class. And add this controller in your custom camera view. and custom camera view is created by the AVFoundation framework.
From what I know, you need to add the tabbar to the appDelegate and then inner views within each tab. Therefore you would have within the appdelegate applicationDidFinishLoading method
// Add the tab bar controller's view to the window and display.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
of course, you need to declare it in the appdelegate.h file
#interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
Search for tabBar tutorials. They must be created BEFORE any NAVIGATION Controller.
Then place all your zbar code in the first view controller.

IOS 5 Using App Delegate To Load a Modal

i'm building an app for ios5 and i have the following problem:
In ios4 when i need to present a login modal view on app start i do the following:
in the AppDelegate i load it in method didFinishLaunchingWithOptions using the referenced View Controller.
#interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate,LoginViewControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController; //THIS
UIView *splashView;
User *user;
}
But now, in ios5 using storyboards, i can't find how to do this because in my AppDelegate i don't have any reference to any view controller and i don't know how to get them.
Any idea about this?
Thanks
But why don't you just add a new Tabviewcontroller in MainStoryboard?
Using storyboards is much easier than writing a code in AppDelegate.

iPhone Development - multiple views in one window.

I want to have a UIView at the top half of my app, and a UITable at the bottom half. If I create a basic window application I can do this using IB. My main problem is that I seem to be only to do this in the delegate file which I would like to avoid.
I repeat the exact same steps I did in delegate in a separate controller and all I get is a blank screen.
0#interface RootViewController : UIWindow {
UIWindow *myWindow;
UIView *headerView;
UITableView *tableView;
}
#property (nonatomic, retain) IBOutlet UIView *headerView;
#property (nonatomic, retain) IBOutlet UITableView *tableView;
#property (nonatomic, retain) IBOutlet UIWindow *myWindow;
#end
I have each of these connect to the right view in rootviewcontroller.xib
I was wondering if anyone had any advice / snippets / examples I could use?
You need to use both the delegate file and Interface Builder. Interface Builder makes a view that binds to your delegate through IBOutlets and IBActions. I would run through several iPhone tutorials found on google before continuing.
Your RootViewController certainly shouldn't be a subclass of UIWindow. You probably want UIViewController for that.