winston
winston

Reputation:

iphone cocoa "error:request for member ____ in something not a structure or union"

this way works:

type1ViewController *viewController = [[type1ViewController alloc] initWithNibName:@"Type1View" bundle:nil];
viewController.parentViewController = self;
self.type1ViewController = viewController;
[self.view insertSubview:viewController.view atIndex:0];
[viewController release];

but this way gives me the error, "request for member parentViewController in something not a structure or union":

type1ViewController *viewController = [[type1ViewController alloc] initWithNibName:@"Type1View" bundle:nil];
self.type1ViewController = viewController;
self.type1ViewController.parentViewController = self;
[self.view insertSubview:viewController.view atIndex:0];
[viewController release];

I don't see why it should be different. What does the compiler see that it does not like? Thanks for your help in advance

Upvotes: 1

Views: 10932

Answers (3)

TALLBOY
TALLBOY

Reputation: 1077

I would also check your NIB file for your Type1ViewController. I've run into issues where this error would get thrown in the Referencing Outlets on the nib were looking for something other than the custom View Controller that I've created.

Upvotes: 0

cduhn
cduhn

Reputation: 17918

If the type1ViewController property of ParentViewController is declared with a class of Type1ViewController, then the first line should read:

Type1ViewController *viewController = [[type1ViewController alloc] initWithNibName:@"Type1View" bundle:nil];

not:

type1ViewController *viewController = [[type1ViewController alloc] initWithNibName:@"Type1View" bundle:nil];

Note the capitalization. I'm actually a bit surprised this compiled without errors or warnings.

Upvotes: 0

Marc Charbonneau
Marc Charbonneau

Reputation: 40517

When you call self.type1ViewController.parentViewController instead of viewController.parentViewController, it's giving you an error because you have self.type1ViewController declared as some superclass, not a type1ViewController. When the compiler looks at this declaration it's not going to find the parentViewController property, so it's giving you the error.

In the first example your viewController is still declared as a type1ViewController, so it works fine. It would actually still work in the second example if you cast it to a type1ViewController, but of course it's better just to change the declaration.

Upvotes: 4

Related Questions