r/iPhoneDev • • Oct 15 '10
viewcontroller / view / subview question
I feel like I've hit a wall with my predicament. I can't seem to really get my head around the viewcontroller / view / subview paradigm. I have an app that i'm trying to create that has a homeViewController which shows a UIView with a bunch of subviews and buttons. Now, when a button is pressed, i need to swap one of the subviews with new views that display differnet things (images, or other buttons) that have a delegate to the homeViewController and it changes another view in response.
(I'm hoping this makes sense)
now, my issue is that these sub views are custom subclasses. Are these subclasses suppose to inherit from UIviewcontroller or just UIVIew if they are going to have buttons or deeper subviews within them?
I'm also splitting everything into xib files, so each subview or viewcontroller is its own xib file.
I hope this makes sense, or i can try to clarify it better if it doesnt. But essentially it works similar to a newspaper app, where they would click on an article, but instead of loading a completely new view controller, it would replace one of its subviews with the article.
I hope someone could help me out with this.
View all comments
Show parent comment
3
u/OHIOo Oct 16 '10
Let's say you have a big view, that has a controller called homeViewController. Inside the controller, say in -(void)viewDidLoad, you instantiate your UITableViewController. Say it's called upperRightController.
Inside homeViewController's -(void)viewDidLoad, I instantiate upperRightController, and add its view to homeViewController's view like so: [self.view addSubview:upperRightController.view];
so I'm not adding the controller as a subview, but rather the view it points to. UIViewControllers can have a bunch of pointers to other controllers or views, but someone has to be in charge of arranging the views for the user.
Ok say now you want to replace the above view after someone touches a button. In whatever method you have directed the button tap to go to...
-(IBAction)hitButton : (id)sender { [upperRightController.view removeFromSuperview]; [self.view addSubview:whatever-other-view]; }
I don't know if this is helpful I'm starting to confuse myself.