Passing info from Facebook to UITabBarController - iphone

When my app first starts, it shows a main page to log in to Facebook. Then, it goes to the UITabBarController. The code that I have in my app delegate is the following:
//this is the .h
#interface NMeAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MainViewController *controller;
UITabBarController *tabBar;
}
#property (nonatomic, retain) IBOutlet UITabBarController *tabBar;
#property (nonatomic, retain) MainViewController *controller;
#property (nonatomic, retain) IBOutlet UIWindow *window;
#end
//this is the .m of the app delegate
#import "NMeAppDelegate.h"
#implementation NMeAppDelegate
#synthesize window;
#synthesize tabBar;
#synthesize controller;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
controller = [[MainViewController alloc] init];
[window addSubview:tabBar.view];
[window addSubview:controller.view];
[window makeKeyAndVisible];
return YES;
}
Inside of MainViewController, I actually have a UserInfo object, which has all of the information that I need for the UITabBarController. The problem is that after getting this info in the UITabViewController, how do I pass this UserInfo to the UITabBarController` or possible the ViewController that is inside the UITabBarController so they were able to access this UserInfo? How to do this?
I hope my question makes sense.

you need to have an instance of your UserInfo object available to the tab bar controller. probably pass it into a instance variable of type UserInfo in your UItabBarController/each view controller whenever you transition into the specified controller.
edit: you should really have this passed into the view Controller it needs to be in (since it doesn't appear you have a custom UITabBarController subclass), or you could use a shared UserInfo variable in your app delegate to keep up with the information.
But as the commenter said, the question is not very clear at all and i could be completely misunderstanding what you want to do.
Hope that helps.

Related

Adding UIViewController subclass with IBOutlet

I have seen this example on Apple's website before, but for some reason, I cannot find it and am brainfarting. I created a TestViewController.h and .m file that subclass from UIViewController and have a .xib. In the TestAppDelegate.h, I have:
#interface TestAppDelegate : NSObject <UIApplicationDelegate> {
TestViewController *rootController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet TestViewController *rootController;
in TestAppDelegate.m, I have:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
Then in my MainWindow.xib, I drag a ViewController, change the class to TestViewController, control drag the outlet from TestAppDelegate to TestViewController. It builds fine, but when I run it I get:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TestViewController 0x4d06570> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label.'
I cannot remember what I'm missing in these steps. Any help would be appreciated. Thanks.
#interface TestAppDelegate : NSObject <UIApplicationDelegate> {
TestViewController *rootController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet TestViewController *rootController;
in TestAppDelegate.m, I have:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
IF IT IS THE CODE YOU ARE REALLY USING THEN ADD FOLLOWING LINE TO YOUR INTERFACE:
UIWindow *window;
AND CHECK IF IT HELPS.
For your window you need to setup you rootViewController. By the way your naming "rootController" is kind of misleading, b/c UIWindow has a property rootViewController.
So to get this to work instead line [self.window addSubview:rootController.view]; you should do this self.window.rootViewController = self.rootController;
If you want to compare your code with a working code just create new project from template. Choose View-Based Application it has the schema you are looking for.
Open the TestViewController.xib and check whether any false outlets are connected there. Select the FilesOwner and go to connection inspector. The false outlets will be shown faded.. In this case, it would be label
Check your outlets in Interface Builder, you have something named "label" that does not exist. Remove the reference to this and you should be good to go.
again checkout....
use the connection inspector and write nib name and class name....in main View Controller.Xib

problem in UINavigation controller

hi to all
i am trying to do a simple navigation based application.this is my code
#import <UIKit/UIKit.h>
#class RootViewController;
#interface jeeAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
RootViewController *viewcontroller;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#property (nonatomic, retain) IBOutlet RootViewController *viewcontroller;
#end
.m file
#import "jeeAppDelegate.h"
#import "RootViewController.h"
#implementation jeeAppDelegate
#synthesize window;
#synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
navigationController=[[UINavigationController alloc]initWithRootViewController:viewcontroller];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
For this code i got "Application tried to push a nil view controller on target <UINavigationController: 0x4b4f5c0>." thanks in advance..
This is fairly simple - at no point have you initialised the view controller that you're attempting to push onto the navigation stack.
i.e.: Before you call..
navigationController=[[UINavigationController alloc]initWithRootViewController:viewcontroller];
...you need to ensure that viewcontroller actually exists, in the sense that you need to alloc and init it.
For example:
// Create our main menu view controller
MainMenuViewController *mainMenuVC = [[MainMenuViewController alloc] init];
// Create our navigational controller and init it with the main menu view controller
navController = [[UINavigationController alloc] initWithRootViewController:mainMenuVC];
[mainMenuVC release];
In the above mainMenuVC is a custom view controller that I've created.
Also, please note that once you've added your view controller to the navigation controller, you can release it as the navigation controller with retain it.

how does this code work, re setting the UITableViewController's data list?

I have this code working, however I don't quite understand how it is managing to set the data source for the UITableViewController? Would this have to be occurring via Interface Builder settings somehow?
That is if you see the line "tableData = [[NSMutableArray alloc] initWithObjects: etc", and the fact that I don't see where my "tableData" instance variable here is actually assigned to be the data for the UITableView....
#interface RootViewController : UITableViewController <NewItemControllerDelegate> {
NSMutableArray *tableData;
}
#end
#implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
tableData = [[NSMutableArray alloc] initWithObjects:#"My Standard View", #"A Different View", nil]; // <== HOW IS THIS MANAGING TO SET THE VIEW WITH THE DATA
}
and for reference
#interface myProjectAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#end
#implementation myProjectAppDelegate
#synthesize window;
#synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
PS (edit) So what I can't quite understand is the linkage between my "NSMutableArray *tableData" variable I declared in the RootViewController header file, and the actual UITableViewController's datasource so to speak? Is there a default "tableData" in a UITableViewController perhaps that is what I'm really setting or something, so I'm not really allocating new NSMutableArray to my variable I created but another one? (hope this makes sense)>
By default, UITableViewController sets itself as the delegate and datasource of its table view. Since your class is a subclass of UITableViewController, it does the same. Of course, this assumes that you have implemented all the UITableViewDataSource methods to actually use the tableData array (which you aren't showing us here).

Using Navigation Controller in a subview of View based Applicatin

Some one please help me with this. I am developing an iPhone app and have stared with View Based Application. I have buttons on my root view screen to take user to other views with their own nibs and classes. On one of those views I need to display a table getting data from SQLite database and then display detail of the selected item depending on the selection from the table. At later stage I also need to add forms to add data.
Now, how to add a Navigation Controller in that view for drill down? Can we convert a View Controller to Navigation Controller just by adding a Navigation bar at the top?
sure
in viewbase application, u can create navigation controller
add the code in delegate.h
#interface test24AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
test24ViewController *viewController;
UINavigationController *nav;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet test24ViewController *viewController;
#property (nonatomic, retain) IBOutlet UINavigationController *nav;
#end
add this delegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
nav=[[UINavigationController alloc]init];
[nav pushViewController:viewController animated:YES];
[self.window addSubview:nav.view];
[self.window makeKeyAndVisible];
return YES;
}
now it will work, u check using nslog(#"%#", self.navigationController); if the result is null then u have problem still.

Where is the UIWindow instantiated in an iPhone app?

When you create an application from the "View-Based" template in the iPhoneSDK the following code is generated. I basically understand what is happening here, but I do not see where window and viewController are instantiated. Any Help?
#class jojojViewController;
#interface jojojAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
jojojViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet jojojViewController *viewController;
#end
===============================================
#implementation Test6AppDelegate
#synthesize window,mainView;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window makeKeyAndVisible];
}
- (void)dealloc {
[window release];
[super dealloc];
}
#end
They come from the MainWindow.xib (or similar) file in your project.
This is the file that in your info.plist is set as the application window. When your application starts this xib is loaded and the viewcontroller and window are unarchived and loaded.
If you look in MainWindow.xib, the window and viewcontroller are assigned to your AppDelegate's window and viewController outlets, which instantiates them when the nib is loaded (right click on the AppDelegate to see it).