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?