Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to organize multiple subviews?

As someone who is fairly new to iPhone development, I've been trying to find good design patterns for managing multiple subviews, specifically where the subviews need the same type of delegate methods to be defined.

For example, I have a view where I need to swap between 2 UITableViews based on user actions. Both UITableViews need a UITableViewControllerDelegate object defined to populate the rows, etc.

Do you more experienced iPhone devs find that overloading the main view controller as the delegate for both subviews is the right way to do things? Currently I have 2 objects defined that each act as a delegate for each UITableView to try to keep things more organized. It accomplishes what I need it to, but is this a good pattern to follow?

I would assume there are some best practices out there to avoid various pitfalls with memory management and fun things like that. Thanks in advance!

like image 233
Loktar Avatar asked Apr 02 '09 22:04

Loktar


1 Answers

You can use views as containers to hold the elements like tables. So in the case you outline, you'd have one container view and swap UITableViews in and out of it...

A good approach would be to have seperate view controllers for each table. Otherwise it just gets too messy trying to keep track of which data set you are supporting across the various table view delegate methods, and makes it harder to do lots of customization to one table that may not apply to another.

The main thing to be aware of when using composed view controllers is the "self.navigationController" and related calls will not return anything (since they are not really children of your navigation controller) so you'll need to pass along that reference or otherwise handle that somewhat differently in the table view controllers.

like image 187
Kendall Helmstetter Gelner Avatar answered Sep 22 '22 01:09

Kendall Helmstetter Gelner