1

我在这里遇到了一些困难,如果您认为我的问题对您来说很容易,请原谅我。我正在尝试使用UISplitView. 左边的第一个视图是a TableView,右边的另一个只是普通视图。

这是我的代码 in AppDelegate.mfor UISplitView

#import "AppDelegate.h"
#import "MasterViewController.h"
#import "DetailViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:        (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

MasterViewController *masterVC = [[MasterViewController alloc]init];
DetailViewController *detailVC = [[DetailViewController alloc]init];
UISplitViewController *splitVC = [[UISplitViewController alloc]init];
[splitVC setViewControllers:[NSArray arrayWithObjects:masterVC,detailVC,nil]];
[self.window setRootViewController:splitVC];

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

现在,我想在 上添加一个导航栏TableView,我只是不知道如果我正在使用如何添加SplitView,但是当我使用单个TableView.

这是我AppDelegate.m使用单个视图应用程序的代码,该应用程序使用TableView. (这是工作)

#import "AppDelegate.h"
#import "ViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
//create UINavigationController
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}

希望你能明白我想说什么。我不能发布图片,因为我没有足够的声誉。TableView再次..问题是“如果我使用了导航控制器,我该如何添加UISplitView?” storyboards如果我使用而不是使用两个文件,您认为对我来说会容易XIB吗?希望您能帮助我。

先谢谢了!

4

1 回答 1

0

try this code

in AppDelegate.h file

    UINavigationController *detailNavigationController;
    UINavigationController  *masterNavigationController;
    UISplitViewController  *HomeSpilitView;
    HomeSpilitViewController *HomeMster;
    HomeDetailsViewController *HomeDetailsViewControllers;

in AppDelegate.m file

     -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        NSMutableArray *array = [NSMutableArray array];

                            HomeSpilitView = [[[UISplitViewController alloc] init]autorelease];

                            HomeMster = [[HomeSpilitViewController alloc] initWithNibName:@"HomeSpilitViewController" bundle:nil];

                            masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:HomeMster] autorelease];
                            HomeMster.title=@"Title home";
                            masterNavigationController.navigationBar.tintColor =[UIColor colorWithRed:255/255.0 green:108/255.0 blue:61/255.0 alpha:0.1];
                            [array addObject:masterNavigationController];


                            HomeDetailsViewController *HomeDetailsViewControllers = [[HomeDetailsViewController alloc] initWithNibName:@"HomeDetailsViewController" bundle:nil];

                            detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:HomeDetailsViewControllers] autorelease];

                            detailNavigationController.navigationBar.tintColor =[UIColor colorWithRed:255/255.0 green:108/255.0 blue:61/255.0 alpha:0.1];
                            HomeDetailsViewControllers.title=@"details title";
                            HomeMster.objHomeDetailsViewcontroller=HomeDetailsViewControllers;
                            HomeSpilitView.delegate = HomeDetailsViewControllers;

                          [array addObject:detailNavigationController];

                          [HomeSpilitView setViewControllers:array];

                          [self.window setRootViewController:HomeSpilitView];
         [self.window makeKeyAndVisible];
         return YES;
    }
于 2013-06-13T10:55:00.710 回答