I have a view开发者_如何学JAVA that I want to use in the MainView and DetialView of a UISplitViewController but I need to be aware of which view it is in so it can behave correctly. Is there any way to know?
Your view's controller will be in one of the two controller hierarchies in the viewControllers
property of the UISplitViewController.
Traverse your controller's parentViewController chain to the UISplitViewController
and then determine which branch it is in.
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (self.splitViewController) {
UISplitViewController split = self.splitViewController;
UIViewController vc = self;
while (split != vc.parentViewController) {
vc = vc.parentViewController;
if (!vc) break;
}
if (vc) {
NSUInteger i = [split.viewControllers indexOfObject:vc];
if (i == 0) {
// self.view is on left side
} else if (i == 1) {
// self.view is on right side
}
}
}
}
精彩评论