带有多个详细视图的UISplitView(带有故事板) [英] UISplitView with Multiple Detail Views (with Storyboard)
问题描述
我一直在尝试使用故事板:
我希望能够在两个不同的详细视图之间切换,具体取决于导航表中选择的单元格。我试图通过创建一个带有自定义setter方法的SplitViewManager来实现这一点,该方法在每次选择不同的单元格时交换详细视图。这与Apple的示例代码使用的方法相同。 SplitViewManager跟随委托。
I want to be able to switch between two different detail views, depending on the cell selected in the navigation table. I've tried to implement this by creating a SplitViewManager with a custom setter method that swaps out the detail views each time a different cell is selected. This is the same approach that Apple's sample code uses. The SplitViewManager follows the delegate.
我认为我的问题是我没有将我的splitViewController.delegate连接到任何东西,所以我不能将splitViewManager分配给任何东西。但我无法弄清楚我甚至会在故事板中连接代表。如果我在这里(几乎肯定)是个白痴,请告诉我。谢谢!
I think my issue is that I haven't connected my splitViewController.delegate to anything, so I can't assign the splitViewManager to anything either. But I can't figure out what I would even connect the delegate to in the storyboard. Please let me know if I'm being an idiot here (almost definitely). Thanks!
我的代码如下:
DFMAppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.splitViewController = (UISplitViewController *)self.window.rootViewController;
self.splitViewManager = (DFMSplitViewManager *)self.splitViewController.delegate;
NSLog(@"split view controller: %@", self.splitViewController); // not null
NSLog(@"split view controller delegate: %@", self.splitViewController.delegate); // is null
NSLog(@"split view manager: %@", self.splitViewManager); // is null.
// But i'm not sure how to assign splitViewController.delegate or splitViewManager in the storyboard.
return YES;
}
DFMSplitViewManager.m:
- (void)setDetailViewController:(UIViewController<SubstitutableDetailViewController> *)detailViewController
{
self.detailViewController = detailViewController;
// Update the split view controller's view controllers array.
// This causes the new detail view controller to be displayed.
UIViewController *navigationViewController = [self.splitViewController.viewControllers objectAtIndex:0];
NSArray *viewControllers = [[NSArray alloc] initWithObjects:navigationViewController, self.detailViewController, nil];
self.splitViewController.viewControllers = viewControllers;
}
DFMMasterViewController.m:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DFMAppDelegate *appDelegate = (DFMAppDelegate *)[[UIApplication sharedApplication] delegate];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
if (indexPath.row == 0) {
NSLog(@"clicked cell 1");
DFMDetailViewController *detailViewController = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
[appDelegate.splitViewManager setDetailViewController:detailViewController];
}
else {
NSLog(@"clicked cell 2");
DFMDetailCollectionViewController *detailCollectionViewController = [storyboard instantiateViewControllerWithIdentifier:@"CollectionViewController"];
[appDelegate.splitViewManager setDetailViewController:detailCollectionViewController];
}
}
推荐答案
转身你可以使用界面构建器将NSObject添加到视图控制器。一旦我这样做,我将NSObject的类更改为DFMSplitViewManager,将其设置为SplitViewController的委托,并且从那里开始非常直接。
Turns out you can use the interface builder to add NSObjects to View Controllers. Once I did that, I changed the NSObject's class to DFMSplitViewManager, set it as the SplitViewController's delegate, and it was pretty straight forward from there.
这篇关于带有多个详细视图的UISplitView(带有故事板)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!