IOS 5 Using App Delegate To Load a Modal - iphone

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.

Related

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.

Loading Tab Controller View in Window Based iPhone App

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.

iPhone Subclassing view controller and IBOutlet UITableView

I have the following problem. I've created a ViewController pretty much like the above
#interface MyViewController : UIViewController {
IBOutlet UITableView *myTableView;
}
#property (nonatomic, retain) IBOutlet UITableView *myTableView;
I've linked myTableView on the Interface Builder to the matching nib's UITableView. and I've subclassed MyViewController to create YourViewController as so:
#interface YourViewController : MyViewController {
}
And then I load from a TabBarController the YourViewController on a tab item. Although I can see that MyViewController is indeed invoked at the end, no table view is displayed on the emulator.
I've tried debugging the MyViewController and it appears the the IBOutlet is nil.
Why is that?
I have encountered major issues with inheritance and IBOutlets and IBAction. I advise you to avoid that, and create shared stuff in another way.
I was hit hard by bugs when getting memory warnings for instance. Outlets and actions didn't get reconnected properly when they were defined in base class vs derived class.
Probably MyViewController's nib file is not loaded at all. Are you using for YourViewController a specific nib file? and in which way are you creating YourViewController.
Can you also try to define an "awakeFromNib" method in YourViewController and then from it call [super awakeFromNib] ?
However to understand your issue you must clearly explain how you load objects and if and where you use Nibs?
If you add it dynamically using code then only it will work. Not using Nib.
the UITableView (ie. your myTableView) needs delegates for data source and and its control.
And your controller needs a link to the Table view in the xib.
declare table delegate protocols in the interface section of your controller.
using IB, link the TableView in your xib to owners file:delegates.
using IB, link the file owner myTableView to the tableView in the xib.
I hope it will help.
Assuming that you have your whole navigation stack in MainWindow.xib
Open MainWindow.xib
Select YourViewController (Or whatever your controller that is subclassing UITableViewController is called)
Select Attributes Inspector
Ensure that the 'NIB Name' property has your correct YourViewController (Or whatever the name) selected
I had this exact same issue, this solved it for me.

How can I access an outlet from my controller class in the app delegate class?

I want to change an image of an UIImageView from the applicationDidFinishLaunching method of the app delegate class. But I am afraid that this class doesnt know much about the controller outlet. What must I do in this case?
You have to define the ViewController that the UIImageView is on, to the AppDelegate Class, so the applicationDidFinishLaunching can reference it.
In the AppDelegate add #class whateverViewController before the interface statement,
and define the instance.
#import <UIKit/UIKit.h>
#class WhateverViewController;
#interface WebDemoAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
WhateverViewController *whateverViewController;
}
Now your app has a reference to whateverViewController. You can then call a method in whateverViewController to change the UIImageView or set the UIImageView directly. Of course this assumes that the whateverViewController is instantiated (e.g. alloc/init or loaded from nib); before you try to set anything, it must exist.
You would probably need to put an outlet for your UIImageView or its controller in your application delegate to make it accessible there.