0
votes

Hi I am working With Ipad Application
I want to Add UISplitView to UIViewController and it Should be in Programmatic approach Can Any one help me how to get out of this
i have added split view to the UIWindow and Worked Fine ,But i need to add UISplitView to UIView Controller, when the User Taps a button in Main Screen it goes to detail View and the detail view should be UISplitView
Thx in Advance

2

2 Answers

2
votes

I would suggest MGSplitViewController. It has a similar API to the regular, but with many extras. One of which is ability to add it as subview.

2
votes

Hi I made it as below it may help you.Just pass parameter as described and you can get slpitview as you desired.

.H file

#import <Foundation/Foundation.h>
@class AppDelegate;
@interface CustomSplitView : NSObject
{
AppDelegate *objAppDelegate;
}
+(UIView *) setSplitView : (UIViewController *)masterView : (UIViewController*)DetailView :(CGRect)frame;
+(void) changeSplitView:(UIViewController *)DetailView :(UINavigationController *)navigationController;

@end

.M file

#import "CustomSplitView.h"
#import "AppDelegate.h"

@implementation CustomSplitView
//*********this return view addsubview on self.view

+(UIView *) setSplitView:(UIViewController *)masterView :(UIViewController *)DetailView :(CGRect)frame
{
objAppDelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate] ;
objAppDelegate.objMasterView=masterView;
objAppDelegate.objDetailView=DetailView;


//Select navigation for every split view
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:objAppDelegate.objMasterView] autorelease];
UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:objAppDelegate.objDetailView] autorelease];
;

objAppDelegate.objSplitView.delegate=objAppDelegate;
objAppDelegate.objSplitView.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController ,nil];

objAppDelegate.objSplitView.view.frame=frame;
return (objAppDelegate.objSplitView.view);
 }

+(void) changeSplitView:(UIViewController *)DetailView :(UINavigationController *)navigationController
{
objAppDelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate] ;

UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:DetailView] autorelease];

objAppDelegate.objDetailView=detailNavigationController ;

// Update the split view controller's view controllers array.
//    NSArray *viewControllers = [[NSArray alloc] initWithObjects:navigationController, objAppDelegate.objDetailView, nil];
//    objAppDelegate.objSplitView.viewControllers= viewControllers;

objAppDelegate.objSplitView.viewControllers = [NSArray arrayWithObjects:navigationController, objAppDelegate.objDetailView ,nil];

}

@end

for set split in your home view

   Masterview *objFirstView = [[Masterview alloc] initWithNibName:@"Masterview" bundle:nil];
    appdel.masterDelegate = objFirstView;
    Detailview *objSecondView = [[Detailview alloc]
                                          initWithNibName:@"Detailview" bundle:nil];

    UIView *objView=[CustomSplitView setSplitView:objFirstView :objSecondView :self.view.frame];
    [self.view addSubview:objView];
    [objFirstView release];
    [objSecondView release];