Given the section of an application which has a UINavigationController and 2 levels of UITableViews (i.e. a row is selected on the root controller which pushes the second controller onto the navigation stack) I have the following questions:
1) There is a User object which is required by both controllers. What is the best way to communicate between the two controllers? I have seen a post on this site which mentions dependancy injection and that the root controller could pass the User object to the second level controller by:
@implementation SecondLevelViewController
-(void) initWithUser: (User *) user {
// myUser is an instance variable
myUser = user;
[myUser retain];
}
In that example the second controller would seem to retain the User whereas I have seen other sources (e.g. the Stanford iPhone development course) which advocate the User being simply assigned, and not retained, in that situation (loose coupling).
I have also seen arguments for a form of delegation where an assigned id object would be used on the second controller (rather than a retained User instance variable as above).
It would be great if someone could clarify this position for me as I am extremely confused by the seemingly conflicting advice in this area. What is the best way for communication between view controllers?
2) My second question also relates to the structuring of the controllers. I have seen examples where the root controller (in the arrangement above) has an array of instantiated second level controllers. Is this normal in a professional application or would there be a significant memory impact for doing things this way (i.e. no lazy loading)? I assume the advantage of the array is a reduction of loading times for the second level controllers?
Thank you for any responses as I am trying to develop things properly rather than hack them together.