Request for member not a structure or union - iOS - iphone

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.

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

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

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.

iPhone navigationController is not displayed

I have a very strange behaviour of my navigation view. What I want is, that from my main view, the user can touch a button, which leads him to the view with the application settings.
Here is the code, responsible for the navigation:
AppDelegate.h
#interface AppDelegate : NSObject {
UIWindow *window;
ViewController *viewController; // My Main View Controller
UINavigationController *navigationController; }
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet ViewController *viewController;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
AppDelegate.m
#synthesize viewController;
#synthesize window;
#synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:viewController.view];
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
}
viewController.h
#import
#import "optionsViewController.h" // the 'settings' view controller
#class AppDelegate;
#interface ViewController : UIViewController {
AppDelegate *appDelegate;
viewController.m
- (IBAction)showOptionsViewController:(UIBarButtonItem *)sender {
// optionsController.theSubjectID = self.theSubjectID;
// [self presentModalViewController:self.optionsController animated:YES];
optionsViewController *optionsController= [[optionsViewController alloc] initWithNibName:#"optionsViewController" bundle:nil];
optionsController.theSubjectID = self.theSubjectID;
[self.navigationController pushViewController:optionsController animated:YES];
[optionsController release];
}
My optionsController is a 'normal' UIViewController. As you see did I change the load of the optionsController from modal to navigation. Could it be, that I missed something here?
Thanks for any hints in advance.
Cheers, René
Have you connected it up in Interface Builder if not you need to alloc/init it before you add it as a subview?

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