my intent is to implement something similar to native iPad Settings app. 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.
So I've tried to extend MultipleDetailViews sample application:
1)SecondDetailViewController
has property navigationController
(which is read-only) set to nil
...
2) So I created a new UINavigationController
and used it to push my controllers, but that didn't work.
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.
Am I trying something that is not possible without implementing custom UISplitViewController
? Was I misled by the sample code that for SecondDetailViewController
has UINavigationBar
?
To be able to do this you have to push the viewController on to each viewController in the array. 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/
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. I could overlay the data on one viewcontroller but was seeking a better solution. 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:
- (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 ([[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"
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
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.
精彩评论