I want to create two side by side views to add to my viewcontroller's view. To keep from repeating code, I am trying to write a generic method to create the two views for me. However, this code isn't working for me. Both view1 and view2 are ivars.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self makeView:view1];
[self makeView:view2];
}
- (void)makeView:(UIView*)view {
CGRect frame = self.view.bounds;
frame.size.height = frame.size.height/2;
if (view == view2) {
frame.origin = CGPointMake(0, frame.size.height);
}
view = [[UIView alloc] initWithFrame:frame];
[self.view addSubview:view];
}
I think the issue might deal with the line view == view2, some sort of variable reference error. view == view2 always evaluates to true, so view1 never shows up. And in later parts of the code view1 and view2 are nil.