Object addSubview only works in viewDidLoad

Posted by DecodingSand on Stack Overflow See other posts from Stack Overflow or by DecodingSand
Published on 2010-06-16T07:32:32Z Indexed on 2010/06/17 12:13 UTC
Read the original article Hit count: 306

Filed under:
|

Hi, I'm new to iPhone dev and need some help with adding subViews.

I have a reusable object that I made that is stored in a separate .h .m and xib file. I would like to use this object in my main project's view controller. I have included the header and the assignment of the object generates no errors. I am able to load the object into my main project but can only do things with it inside my viewDidLoad method. I intend to have a few of these objects on my screen and am looking fora solution that is more robust then just hard wiring up multiple copies of the shape object.

As soon as I try to access the object outside of the viewDidLoad it produces a variable unknown error - first use in this function.

Here is my viewDidLoad method:

shapeViewController *shapeView = [[shapeViewController alloc] initWithNibName:@"shapeViewController" bundle:nil];

[self.view addSubview: shapeView.view];

// This is the problem line // This code works changes the display on the shape object

[shapeView updateDisplay:@"123456"];

---- but the same code outside of the viewDidLoad generates the error.

So to sum up, everything works except when I try to access the shapeView object in the rest of the methods.

Thanks in advance

© Stack Overflow or respective owner

Related posts about error

Related posts about uiview