无法使用UISplitView在TableView上添加NavigationController

时间:2013-06-13 10:49:04

标签: ios uinavigationcontroller uisplitviewcontroller

我在这里度过了一段时间,请原谅我,如果你认为我的问题对你来说那么容易。 我正在尝试使用UISplitView创建应用。左边的第一个视图是TableView,右边的另一个是普通视图。

这是AppDelegate.m 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 1}}。

这是我在 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; } 的单个View应用程序。 (这是有效的)

TableView

希望你能理解我想说的话。由于我没有足够的声誉,我无法发布图片。 AGAIN ..问题是“如果我使用UISplitView,如何在storyboards中添加导航控制器?” 如果我使用XIB而不是使用两个{{1}}文件,您认为这对我来说会很容易吗?希望您能帮助我。

先谢谢!

1 个答案:

答案 0 :(得分:0)

试试这段代码

AppDelegate.h 文件

    UINavigationController *detailNavigationController;
    UINavigationController  *masterNavigationController;
    UISplitViewController  *HomeSpilitView;
    HomeSpilitViewController *HomeMster;
    HomeDetailsViewController *HomeDetailsViewControllers;
AppDelegate.m 文件

中的

     -(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;
    }