UIViewController中的UISplitView

时间:2011-07-26 13:09:51

标签: ipad uisplitviewcontroller

您好我正在使用Ipad应用程序
我想将UISplitView添加到UIViewController,它应该采用Programmatic方法 任何人都可以帮助我摆脱这个问题 我已将分割视图添加到UIWindow和Worked Fine,但我需要将UISplitView添加到UIView Controller, 当用户点击主屏幕中的按钮时,它会转到详细视图,详细视图应该是UISplitView
Thx提前

2 个答案:

答案 0 :(得分:2)

您好我在下面做了它可能对您有所帮助。只需按照说明传递参数,您可以根据需要获得slpitview。

.H文件

#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文件

#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

用于在家庭视图中设置拆分

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

答案 1 :(得分:2)

我建议使用MGSplitViewController。它具有与常规API类似的API,但有许多附加功能。其中之一是能够将其添加为子视图。