views:

198

answers:

1

Hi all, I've been banging my head with this one this evening and am sure it's something very simple that I've missed

I've created a new project with the appdelegate and a view controller class as below. The view controller synthesises the property in the .m, and the app delegate header imports the view controller .h file. Code below:

View controller header:

@interface untitled : UIViewController {
    NSString *string;
}
@property (nonatomic, retain) NSString *string;

App delegate:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
 testViewController = [[untitled alloc] initWithNibName:@"untitled" bundle:nil];
 testViewController.string = @"Testing String";
    [window addSubview:testViewController.view];
    [window makeKeyAndVisible];
}

Can someone please help and point out the obvious mistake as to why setting the string property fails here with the error mentioned? Is it because of being inside this method? I've never had issues setting properties in other methods before after initing a view controller.

Thanks.

+4  A: 

The error is saying it does not understand that the class has that property. It means you have either the wrong class or that it knows nothing about the class.

So, you need to add:

#import "untitled.h"

in your application delegate - also, you need to have the variable be of type "untitled" (I am pretty sure you declared the type as UIViewController and not untitled):

 untitled * testViewController = (untitled *)[[untitled alloc] initWithNibName:@"untitled" bundle:nil];

By the way, by convention you should always start class names in uppercase.

Kendall Helmstetter Gelner
Ah well the untitled.h is already imported in the app delegate header, so it knows about the view controller class itself - if i remove the line to assign the property then it loads and displays the untitled nib correctly.untitled is just the lazy name I gave the view controller class in this example :)
Tom
Just realised what you meant with the type, that solved it - thanks!
Tom