PDA

View Full Version : Recreating Apple's HW Code Error "undeclared (first use in this function)"




Hot Sauce79
Jul 1, 2008, 09:35 AM
Here is my code. It is completely identical to mac's code except for "viewController" replaces apple's "myViewController." I have retyped the full code in all of the files and I arranged the .xib files the same way. For some reason though the mac program doesn't have an error with 'aViewController' but my program does. Like I said everything is identical. Help would be greatly appreciated.

#import "newtry1AppDelegate.h"
#import "newtry1ViewController.h"

@implementation newtry1AppDelegate

@synthesize window;
@synthesize viewController;


- (void)applicationDidFinishLaunching: (UIApplication *)application {

viewController *aViewController = [[viewController alloc] initWithNibName:@"newtry1ViewController" bundle:[NSBundle mainBundle]];
//the error is here "error:'aViewController' undeclared (first use in this function)"

self.viewController = aViewController;
[aViewController release];

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];

UIView *controllerView = [viewController view];
[window addSubview:controllerView];
[window makeKeyAndVisible];
}


- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end



thank you to those who try to help me



lee1210
Jul 1, 2008, 09:50 AM
I don't know what example you are working off of, but it seems that aViewController should be of type:
NSViewController *
Not viewController * (as i don't think this exists as a type, unless you defined it)

-Lee

ElectricSheep
Jul 1, 2008, 09:50 AM
@synthesize viewController; implies that viewController is a container. viewController *aViewController = [[viewController alloc] ...]; implies that viewController is a type (a class). You can't have it both ways, so which is it? Is viewController a type, or a container?

Hot Sauce79
Jul 1, 2008, 10:03 AM
I don't know what example you are working off of, but it seems that aViewController should be of type:
NSViewController *
Not viewController * (as i don't think this exists as a type, unless you defined it)

-Lee

The example I am using is the one off of the apple website that has the download for the Iphone SDK. They have sample codes towards the bottom.

about the NSViewController * I'm uncertain as to whether that is right or not. It may be and ill try it, but if you go and look at apple's code it is as i put it.

Hot Sauce79
Jul 1, 2008, 10:06 AM
@synthesize viewController; implies that viewController is a container. viewController *aViewController = [[viewController alloc] ...]; implies that viewController is a type (a class). You can't have it both ways, so which is it? Is viewController a type, or a container?

It is a class, here is the corresponding header file.

#import <UIKit/UIKit.h>

@class ViewController;

@interface newtry1AppDelegate : NSObject <UIApplicationDelegate> {
IBOutlet UIWindow *window;
IBOutlet ViewController *viewController;
}

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) ViewController *viewController;

@end

If you want I could post Mac's code that they provided for these files.

these are the Delegate files that i am working with by the way

gnasher729
Jul 1, 2008, 10:10 AM
It is a class, here is the corresponding header file.

#import <UIKit/UIKit.h>

@class ViewController;


ViewController is a class. viewController is not a class.

Hot Sauce79
Jul 1, 2008, 10:11 AM
ok i found something new, they were using upper case and lower case letters for different things with the same name. I corrected my error. Now there seems to be a problem with running it because it likes to quit unexpectedly. Thanks for helping though because you made me think about that when you said it couldn't be both.

lee1210
Jul 1, 2008, 10:12 AM
ViewController *
is not the same as:
viewController *

C and Objective-C are case sensitive, they are not like Fortran (thankfully... trying reading 1000s of lines written in all caps).

-Lee

Hot Sauce79
Jul 1, 2008, 10:25 AM
well at least it runs now, but it isnt exactly doing what I want it to do.

It is supposed to open up, show the origonal MainWindow.xib, and then it should switch to newtry1ViewController.xib. However, it doesn't seem to be switching to the other Nib file.

It either freezes my iphone simulator or it "quits unexpectedly."

Any ideas as to how to fix this?

Sorry I'm new at this and I am supposed to learn it as a job and eventually start writing tutorials for it so I need all of the help that I can get.

Thank you so much for helping!

Hot Sauce79
Jul 1, 2008, 10:26 AM
Im going on lunch break now as well. I should be back in 1-1.5 hours.

Hot Sauce79
Jul 1, 2008, 12:32 PM
OK I gave up on that one and I am rewriting the program and plan on paying better attention to the capitalization. Thank You all for your help and I will be sure to keep in mind what you told me with my problem earlier.