- (void)viewDidLoad {
BlueViewController *blueController = [[BlueViewController alloc] initWithNibName@"BlueView" bundle:nil];
self.blueViewController = blueController; //blueViewController set to var above
[self.view insertSubview:blueController.view atIndex:0];
[blueController release];
[super viewDidLoad];
}
not understanding this code very well. How come i am inserting the subview blueController and not self.blueViewController
also what difference does it make if I don’t use self. Not even sure why self is used. I interpret it as I am setting the blueViewController property of the current View Controller to the blueController instance but why would I do that. The book I am reading from does not explain such things in detail. It is pretty much monkey do this.
since you have executed the assignment:
those two variables are the same, so
would be just the same as the code you posted.
if you don’t assign to
self.blueController, then your variable is just a simple variable local to that function. By having a propertyself.blueControllerand storing there a value, you can use that value in all of the selectors (functions) of your class.check the code and you will see that
self.blueControlleris used also in other functions. e.g., at some point you might decide you like making that subview hidden, or you want to remove it, etc. All of this you can do only if you have a pointer to the controller accessible to your class functions.