views:

27

answers:

2

I have a view controller, which creates 2 view controllers inside it. Inside each of these child controllers I wanted to create a property, which would be public, and accessible from the parent controller.

I am using the following method

TableViewController.h

@interface TableViewController : UITableViewController {
    NSInteger projectId;
}

@property NSInteger projectId;

TableViewController.m

@implementation TableViewController

@synthesize projectId;

...

@end

I was then expecting the parent view controller to be able to create the child and access the parentId variable:

ParentViewController.h

#import "TableViewController.h"
@interface ParentViewController : UIViewController {
    TableViewController* tableViewController;
}

@property (nonatomic, retain) TableViewController* tableViewController;

ParentViewController.m

@implementation ParentViewController

- (void)viewDidLoad {
    self.tableViewController = [[TableViewController alloc] initWithNibName:@"TableViewController" bundle:nil];
    self.tableViewController.projectId = 100;
}

However, the property projectId is not found, and returns the error - Request formember 'projectId'in something not a structure or a union.

If I change the line

self.tableViewController.projectId = 100;

to

[self.tableViewController setProjectId:100];

I get the warning - 'TableViewController' may not respond to '-setProjectId'

I am compiling this within XCode 4 preview 2, but also have the same issue within XCode 3.2

I am obviously missing something obvious, but cannot work out what it is.

Why can I not access this property?

A: 

Did you #import your .h files in the corresponding .m files?

Pumbaa80
Apparently so. Definitely looks like it to me. I think I will look at it with fresh eyes in the morning.
Xetius
A: 

Turns out that I had 2 copies of the TableViewController files. One had all my changes, the other was empty. I had initially created the file in the wrong directory and when I deleted it I had just removed it from the project.

Once I deleted these bogus files, everything worked fine.

Silly me!

Xetius
What an annoyance! I thought Xcode would warn you in situations like that. Hopefully, this will get better in Xcode4
Pumbaa80
Yes, annoyingly the file I was editing in XCode 4 was not the one included with the compile. How odd.
Xetius