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

Discussion in 'iOS Programming' started by Hot Sauce79, Jul 1, 2008.

  1. macrumors newbie

    Jul 1, 2008
    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:mad:"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];

    thank you to those who try to help me
  2. macrumors 68040


    Jan 10, 2005
    Dallas, TX
    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)

  3. macrumors 6502


    Feb 18, 2004
    Wilmington, DE
    @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?
  4. thread starter macrumors newbie

    Jul 1, 2008
    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.
  5. thread starter macrumors newbie

    Jul 1, 2008
    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;


    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
  6. macrumors G5


    Nov 25, 2005
    ViewController is a class. viewController is not a class.
  7. thread starter macrumors newbie

    Jul 1, 2008
    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.
  8. macrumors 68040


    Jan 10, 2005
    Dallas, TX
    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).

  9. thread starter macrumors newbie

    Jul 1, 2008
    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!
  10. thread starter macrumors newbie

    Jul 1, 2008
    Im going on lunch break now as well. I should be back in 1-1.5 hours.
  11. thread starter macrumors newbie

    Jul 1, 2008
    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.

Share This Page