xcode 具有多个细节视图控制器的 UISplitViewController
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15104404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UISplitViewController with multiple Detail View Controller
提问by Nazia Jan
I am making a splitView application and i want different detail view controllers for all i have studies a lot found that use apples MultipleDetailView Controllers but it is not fully adopted so that any one can use it so is there any way to get this done mean different detailViewController for all.
我正在制作一个 splitView 应用程序,我想要不同的细节视图控制器,我已经研究了很多发现使用苹果 MultipleDetailView 控制器,但它没有被完全采用,所以任何人都可以使用它,所以有什么方法可以完成这项工作意味着不同所有的 detailViewController。
回答by Nitin Gohel
hi Nazia i just found solution From http://kshitizghimire.com.np/uisplitviewcontroller-multipledetailviews-with-navigation-controller/
嗨,Nazia,我刚刚从http://kshitizghimire.com.np/uisplitviewcontroller-multipledetailviews-with-navigation-controller/找到了解决方案
you can do like:-
你可以这样做:-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch.
self.splitViewController =[[UISplitViewController alloc]init];
self.rootViewController=[[RootViewController alloc]init];
self.detailViewController=[[FirstDetailViewController alloc]init];
UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];
self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
self.splitViewController.delegate=self.detailViewController;
// Add the split view controller's view to the window and display.
[window addSubview:self.splitViewController.view];
[window makeKeyAndVisible];
return YES;
}
-(void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
When a row is selected, set the detail view controller's detail item to the item associated with the selected row.
*/
NSUInteger row = indexPath.row;
[self.appDelegate.splitViewController viewWillDisappear:YES];
NSMutableArray *viewControllerArray=[[NSMutableArray alloc] initWithArray:[[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] viewControllers]];
[viewControllerArray removeLastObject];
if (row == 0) {
self.firstDetailViewController=[[[FirstDetailViewController alloc] init]autorelease];
[viewControllerArray addObject:self.firstDetailViewController];
self.appDelegate.splitViewController.delegate = self.firstDetailViewController;
}
if (row == 1) {
self.secondDetailViewController=[[[SecondDetailViewController alloc]init]autorelease];
[viewControllerArray addObject:self.secondDetailViewController];
self.appDelegate.splitViewController.delegate = self.secondDetailViewController;
}
[[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] setViewControllers:viewControllerArray animated:NO];
[self.appDelegate.splitViewController viewWillAppear:YES];
[viewControllerArray release];
}
you can also check this Demo http://kshitizghimire.com.np/wp-content/uploads/2011/01/MultipleDetailViewsWithNavigator.zip
您还可以查看此演示http://kshitizghimire.com.np/wp-content/uploads/2011/01/MultipleDetailViewsWithNavigator.zip