"Best" way to structure long views on iPhone
I'm working on an iPhone app that (among other things) has a detail view for records with lots of attributes and lots of related records. Rather than having one really long scroll view or table开发者_如何学Python view, I am thinking it might be easiest to break the detail view into several separate views (some UIViews, some UITableViews, etc) that each display one grouping of the record's attributes or related records.
I use a UINavigationController to control view changes in my app, and I could put a UISegmentedController the toolbar
to control which group of the record's attributes or relationships to display. This would look like:
I'm thinking this is the best way to go, but how do I populate the Content Area without pushing and popping from the navigation controller?
Is this even the "right" way to do this? Is this needlessly complex? Or is there some native controller that I should be considering instead?
Thanks!
Firstly, I would recommend looking for some way to hack the UISegmentedControl onto a UITabBarController, replacing the UITabBar, being that this would appear to yield the behavior you desire without further effort. However, this does not seem possible at the moment. Therefore, I would recommend using a custom view where you would like the content to go, with essentially one property, a UIView. When that UIView is set, the contentview should remove all of its subviews and add the view as its sole subview, and scale it to fill the entire contentview. These views should be chosen based on an array of UIViewControllers (with indexes matching the UISegmentedControl's).
That would be fine, I think. You'd have a view controller class roughly like:
@interface MyDetailViewController : UIViewController {
// a blank, full-area view that will serve as the superview for modeSelector
// and your detail views
UIView *rootView;
UISegmentedControl *modeSelector;
// placeholder to track the current view, not strictly necessary.
UIView *currentDetailView;
UIView *firstModeView;
UIView *secondModeView;
// ... etc.
}
You'd probably store each UIView composition in its own nib, and load them manually with [NSBundle loadNibNamed:owner:options:].
Add IBActions to your view controller to show each view:
-(void)showSecondModelView:(id)sender {
if(currentDetailView != secondModeView) {
[self.rootView addSubview:secondModeView];
// alternatively, you could keep all of your detail views
// on the root view, and use bringSubviewToFront
[self.currentDetailView removeFromSuperview];
self.currentDetailView = secondModeView;
}
return;
}
Connect your actions in IB or with [modeSelector addTarget:action:forControlEvents] and you should be good to go.
精彩评论