Adding UIViewController subclass with IBOutlet - iphone

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

Related

Request for member not a structure or union - iOS

I wanted to change the default view that loads up in MainWindows.xib. So I added a new instance variable for the class I want to add the view of here is the code in .h
#class Table;
#interface GameUIAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
Table *viewController; //changed the class
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet Table *viewController;
and then in the MainWidow.xib I changed the class name and xib on the UIView
in the .m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[self.window addSubview:viewController.view]; //error here
[self.window makeKeyAndVisible];
return YES;
}
what am I missing and please explain me why am I getting this error
You need to #import "Table.h" in your .m file.

UIViews not showing in my window based template?

UIView not shown on my window based template?
I am creating an app for this a was use the window based template and a view controller and for checking drop label but after execution it appears like clean white window.
in delegate header file i do this
#import "First_View.h"
#class First_View;
#property (nonatomic, retain) First_View *viewcontroller;
And in delegate.m
#synthesize viewcontroller=_viewcontroller;
//in implementation
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.viewcontroller; /*/**main line code here**/*/
[self.window makeKeyAndVisible];
return YES;
}
You can add the ViewController View to the window like that:
[self.window addSubView:self.viewcontroller.view];
And the view Controller should have an outlet if you are creating it using Interface Builder and don't forget to connect it:
#property (nonatomic, retain) IBOutlet First_View *viewcontroller;

iPhone Loading Different Views

I have to xibs, and I want to load which one the user wants in the settings. I'm just working on actually loading them and how would this been done.
This is the function in the delegate which I think would be where this happens.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
This is the delegate header file.
#import <UIKit/UIKit.h>
#class myAppViewController;
#interface myAppAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
myAppViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet myAppViewController *viewController;
#end
So lets say I have a xib created called modernTheme, how would I load that or the myAppViewController. If someone could do this in a generic if statement, that would be great.
This looks like your viewController is being created 'in Interface Builder'. Instead of that you could create the ViewControllers yourself and add them dynamically. Your application:didFinishLaunchingWithOptions: could look something like this:
UIViewController *viewController;
if (showModernTheme) { // from your configuration
viewController = [[YourViewControllerA alloc] initWith…];
} else {
viewController = [[YourViewControllerB alloc] initWith…];
}
// assuming YourViewControllerA + B are inheriting from UIViewController
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
Hope that helps
–f

Passing info from Facebook to UITabBarController

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.

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).