[英]How can I push view controllers in detail view of Apple's sample MultipleDetailViews?
my intent is to implement something similar to native iPad Settings app. 我的目的是实现类似于原生iPad设置应用程序的东西。 Settings use
UITableViewController
and, as such, in detail view can drill down to subviews, however I want to be able to push a view controller via button tap in my detail view. 设置使用
UITableViewController
,因此,在详细视图中可以深入查看子视图,但是我希望能够通过详细视图中的按钮点击来推动视图控制器。
So I've tried to extend MultipleDetailViews sample application: 所以我试图扩展MultipleDetailViews示例应用程序:
1) SecondDetailViewController
has property navigationController
(which is read-only) set to nil
... 1)
SecondDetailViewController
具有属性navigationController
(只读)设置为nil
...
2) So I created a new UINavigationController
and used it to push my controllers, but that didn't work. 2)所以我创建了一个新的
UINavigationController
并使用它来推送我的控制器,但这不起作用。
My code: 我的代码:
if (!self.myNavigationController) {
self.myNavigationController = [[UINavigationController alloc] initWithRootViewController:self];
}
FirstDetailViewController *controller = [[FirstDetailViewController alloc] initWithNibName:@"FirstDetailView" bundle:nil];
[[self myNavigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
Also tried just init
method on UINavigationController
, but didn't work as well. 也尝试了
UINavigationController
上的init
方法,但是也没有用。
Am I trying something that is not possible without implementing custom UISplitViewController
? 我是否尝试过在没有实现自定义
UISplitViewController
情况下无法实现的UISplitViewController
? Was I misled by the sample code that for SecondDetailViewController
has UINavigationBar
? 我是否被示例代码误导为
SecondDetailViewController
有UINavigationBar
?
I was searching for the solution to a similar problem. 我正在寻找类似问题的解决方案。 In my case i wanted tableview to link to multiple detailviews depending on the selection.
在我的情况下,我希望tableview链接到多个详细视图,具体取决于选择。 I could overlay the data on one viewcontroller but was seeking a better solution.
我可以在一个viewcontroller上覆盖数据但是正在寻求更好的解决方案。 Here is what i did.
这就是我做的。 Its simple and works much better then some of the complex and outdated options i found so far.
它的简单和工作比我迄今为止发现的一些复杂和过时的选项要好得多。
I simply gave a storyboard ID in the identity inspector to the viewcontroller that i wanted showing up in the detailview ("second") and upon didSelectRowAtIndexPath i simply added: 我只是在身份检查器中将一个故事板ID提供给我想要显示在detailview(“second”)中的viewcontroller,并在didSelectRowAtIndexPath上添加:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TimeDetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];
[[self.splitViewController.viewControllers objectAtIndex:1] pushViewController:detail animated:YES];
}
So when someone presses a cell in the master view, the detail view is pushed. 因此,当有人按下主视图中的单元格时,将推送详细视图。
A simple if statement can switch which view is shown: 一个简单的if语句可以切换显示的视图:
if ([[self.selfRootMenuArray objectAtIndex:indexPath.row] isEqual: @"Second Choice"]) {
TimeDetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];
[[self.splitViewController.viewControllers objectAtIndex:1] pushViewController:detail animated:YES];
else if ([[self.selfRootMenuArray objectAtIndex:indexPath.row] isEqual: @"First Choice"]) {
TimeDetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"first"];
[[self.splitViewController.viewControllers objectAtIndex:1] pushViewController:detail animated:YES];
};
You could simply use buttons, switches or anything else instead of a table view but the point is that by adding a "Storyboard ID" in the "Identity Inspector" 你可以简单地使用按钮,开关或其他任何东西而不是表格视图,但重点是通过在“身份检查器”中添加“故事板ID”
and simply instantiating the view controller by referencing the "Storyboard ID" and then pushing it to the split view controller at index 1 (detail side) its simple and quick 并简单地通过引用“故事板ID”来实例化视图控制器,然后将其推送到索引1(细节侧)的拆分视图控制器,它简单快捷
TimeDetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];
[[self.splitViewController.viewControllers objectAtIndex:1] pushViewController:detail animated:YES];
To be able to do this you have to push the viewController on to each viewController in the array. 为了能够这样做,你必须将viewController推送到数组中的每个viewController。 Like so:
像这样:
[[self.appDelegate.splitViewController.viewControllers objectAtIndex:0] pushViewController:rootLevel1 animated:YES];
[[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] pushViewController:detailLevel1 animated:YES];
Credit and Code: http://kshitizghimire.com.np/uisplitviewcontroller-multipledetailviews-with-navigation-controller/ 信用和代码: http : //kshitizghimire.com.np/uisplitviewcontroller-multipledetailviews-with-navigation-controller/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.