Iphone cocoa ": request for a 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 path gives me an error: "request for parentViewController for member is not a struct 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 understand why it should be different. What does the compiler see that it doesn't like it? Thanks for your help in advance

+1


a source to share


3 answers


When you call self.type1ViewController.parentViewController

instead viewController.parentViewController

it gives you an error because you have self.type1ViewController

declared as some superclass and not type1ViewController. When the compiler looks at this declaration, it will not find the parentViewController property, so it will give you an error.



In the first example, your viewController is still declared as type1ViewController, so it works fine. In the second example, this will still work if you apply it to type1ViewController, but of course it's better to just change the declaration.

+4


a source


If the type1ViewController property of the ParentViewController is declared as a Type1ViewController class, then the first line should look like this:

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

      

not



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

      

Pay attention to the capitalization. I'm actually a little surprised that this compiled with no errors or warnings.

0


a source


I would also check your NIB file for your Type1ViewController. I ran into problems getting this error on referencing weekend on nib looking for something other than a custom view controller I created.

0


a source







All Articles