简体   繁体   English

如何在Apple的SampleDetailViews样本的详细视图中推送视图控制器?

[英]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 ? 我是否被示例代码误导为SecondDetailViewControllerUINavigationBar

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];

You can do it using: 你可以使用:

showDetailViewController(viewController, sender: nil)

Documentation from Apple about it is here . 关于Apple的文档就在这里

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.

相关问题 在Apple的MultipleDetailViews示例中调用numberOfRowsInSection但不调用cellForRowAtIndexPath - numberOfRowsInSection called but not cellForRowAtIndexPath in MultipleDetailViews sample of apple UISplitViewController的详细信息视图推送错误 - UISplitViewController's detail view push error 如何为表格视图实现图像细节视图? - How can I implement an image detail view for my table view? 如何从Masterview推送到故事板的详细视图? - How to push from Masterview to detail view with storyboard? 如何从各种视图控制器访问存储在App Delegate中的数据? - How can I access data that's stored in my App Delegate from my various view controllers? 如何将一个新的视图实例推到同一视图之上? - How can I push a new instance of a view on top of the same view? 从搜索显示控制器的表视图中推送详细信息控制器 - Push detail controller from search display controller's table view 将UIWebView推送为详细视图(表) - Push UIWebView as detail view (table) 如何使用自动布局在两个子视图控制器之间移动? - How can I move across two child view controllers with autolayout? 直接在不同的细节视图控制器之间选择 - directly segueing between different detail view controllers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM