I have quite a question to ask here so I hope someone can be of assistance and help with a detailed explanation on the matter:
- I have a User object that downloads a user's profile from the server.
- I have a custom TabBarController which has a infinite scrollable tabbar as well as a pageview controller above it that displays 10 different view controllers that I want to access the different information that is held in the User object.
- As of right now, the data is lazy loaded in each of the 10 view controllers as their viewDidLoad method is called. What I need to do now is, instead of lazy loading the User data, is to download it all at once and have the 10 different view controllers access the already downloaded data in the User object.
Here is the structure of it all:
CustomTabBarViewController
PageContentViewController
The PageContentViewController holds a reference to the 10 ViewControllers and CustomTabBarViewController delegates which one it shows depending on which way you scroll or which tab bar you select.
From what I understand, when loading any of the 10 View Controllers I should write something like..
ViewController* vc = [[ViewController alloc] initWithUser:_user];
I need to create this init method obviously but this is generally what I want to do to pass the user object into the View Controller. Mind you, I only want to pull the user data from the server once!
UPDATE
TabBarViewController
-(void)setupContainerView
{
_containerView = [[UIView alloc] initWithFrame:CGRectMake(0, scrollViewHeight, self.view.frame.size.width, self.view.frame.size.height - scrollViewHeight)];
_containerView.backgroundColor = Rgb2UIColor(230, 230, 230);
_containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:_containerView];
//Load the view controllers from the storyboard and add them to the array.
UIStoryboard *storyboard = self.storyboard;
General_TableViewController *vc1 = [storyboard instantiateViewControllerWithIdentifier:@"GeneralTVC"];
Allergies_TableViewController *vc2 = [storyboard instantiateViewControllerWithIdentifier:@"AllergiesTVC"];
MedicalHistory_TableViewController *vc3 = [storyboard instantiateViewControllerWithIdentifier:@"MedicalHistoryTVC"];
Medications_TableViewController *vc4 = [storyboard instantiateViewControllerWithIdentifier:@"MedicationsTVC"];
FamilyHistory_TableViewController* vc5 = [storyboard instantiateViewControllerWithIdentifier:@"FamilyHistoryTVC"];
XRays_CollectionViewController* vc6 = [storyboard instantiateViewControllerWithIdentifier:@"XRaysCVC"];
Charts_CollectionViewController* vc7 = [storyboard instantiateViewControllerWithIdentifier:@"ChartsCVC"];
NextOfKin_TableViewController* vc8 = [storyboard instantiateViewControllerWithIdentifier:@"NextOfKinTVC"];
OrganDonor_TableViewController* vc9 = [storyboard instantiateViewControllerWithIdentifier:@"OrganDonorTVC"];
DoNotResuscitate_TableViewController* vc10 = [storyboard instantiateViewControllerWithIdentifier:@"DoNotResuscitateTVC"];
_subViewControllers = [NSArray arrayWithObjects:vc1,vc2,vc3,vc4,vc5,vc6,vc7,vc8,vc9,vc10, nil];
}
PageContentViewController
-(void)setupContainerView
{
_containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_containerView.backgroundColor = [UIColor purpleColor];
_containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:_containerView];
//Load the view controllers from the storyboard and add them to the array.
UIStoryboard *storyboard = self.storyboard;
General_TableViewController *vc1 = [storyboard instantiateViewControllerWithIdentifier:@"GeneralTVC"];
Allergies_TableViewController *vc2 = [storyboard instantiateViewControllerWithIdentifier:@"AllergiesTVC"];
MedicalHistory_TableViewController *vc3 = [storyboard instantiateViewControllerWithIdentifier:@"MedicalHistoryTVC"];
Medications_TableViewController *vc4 = [storyboard instantiateViewControllerWithIdentifier:@"MedicationsTVC"];
FamilyHistory_TableViewController* vc5 = [storyboard instantiateViewControllerWithIdentifier:@"FamilyHistoryTVC"];
XRays_CollectionViewController* vc6 = [storyboard instantiateViewControllerWithIdentifier:@"XRaysCVC"];
Charts_CollectionViewController* vc7 = [storyboard instantiateViewControllerWithIdentifier:@"ChartsCVC"];
NextOfKin_TableViewController* vc8 = [storyboard instantiateViewControllerWithIdentifier:@"NextOfKinTVC"];
OrganDonor_TableViewController* vc9 = [storyboard instantiateViewControllerWithIdentifier:@"OrganDonorTVC"];
DoNotResuscitate_TableViewController* vc10 = [storyboard instantiateViewControllerWithIdentifier:@"DoNotResuscitateTVC"];
_subViewControllers = [NSArray arrayWithObjects:vc1,vc2,vc3,vc4,vc5,vc6,vc7,vc8,vc9,vc10, nil];
vc1 = nil;
vc2 = nil;
vc3 = nil;
vc4 = nil;
vc5 = nil;
vc6 = nil;
vc7 = nil;
vc8 = nil;
vc9 = nil;
vc10 = nil;
_selectedViewController = [_subViewControllers objectAtIndex:self.pageIndex];
if (_selectedViewController.parentViewController == self)
{
// nowthing to do
return;
}
// adjust the frame to fit in the container view
_selectedViewController.view.frame = _containerView.bounds;
// make sure that it resizes on rotation automatically
_selectedViewController.view.autoresizingMask = _containerView.autoresizingMask;
// add as child VC
[self addChildViewController:_selectedViewController];
// add it to container view, calls willMoveToParentViewController for us
[_containerView addSubview:_selectedViewController.view];
// notify it that move is done
[_selectedViewController didMoveToParentViewController:self];
}