Reputation: 570
i have a requirement to load multiple viewControllers on detailViewController on a splitView. somethingLike
when the alarm is on , so that i can push the related view controller on detailView. left side view is a uitableview.
my code is here on AppDelegate.m
#import "splitDetailViewController.h"
#import "splitTableViewController.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
splitTable=[[splitTableViewController alloc]initWithStyle:UITableViewStyleGrouped];
UINavigationController *splitTableNav=[[UINavigationController alloc]initWithRootViewController:splitTable];
splitDetails=[[splitDetailViewController alloc]initWithNibName:nil bundle:nil];
UINavigationController *splitDetailNav=[[UINavigationController alloc]initWithRootViewController:splitDetails];
self.splitViewController.delegate=splitDetails;
splitViewController=[[UISplitViewController alloc]init];
splitViewController.viewControllers=[NSArray arrayWithObjects:splitTableNav,splitDetailNav, nil];
[self.window addSubview:splitViewController.view];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
sorry, this is the first time am developing iPad apps, am little bit confused about how to use splitview. how will i call the multiple viewControllers on detail view. for timer, alarm,share , each have different view controllers.
hope i will get some help!
Upvotes: 0
Views: 4177
Reputation: 41
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];
Hope it helps
Upvotes: 4
Reputation: 5321
This is my Solution, hope it helps : https://github.com/selfdealloc/MultipleDetailViewsUsingStoryboards
Upvotes: 1
Reputation: 570
okay, myself found one solution, it works fine
http://kshitizghimire.com.np/uisplitviewcontroller-multipledetailviews-with-navigation-controller/
thankyou
Upvotes: 1