1

Bellow i have some code that is place in the app delegate.m and is used to create a c between two ViewControllers. The creation of the tab bar works fine but when i select the setting tab there is no view it is just black.

Here is the code:

import "ViewController.h"
#import "Settings.h"

@implementation AppDelegate

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];

        UITabBarController *tbc = [[UITabBarController alloc]init];

        ViewController *vc1 = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
        Settings *vc2 = [[Settings alloc]init];

        [vc1.tabBarItem setTitle:@"Browse"];
        [vc2.tabBarItem setTitle:@"Settings"];

        [tbc setViewControllers:[NSArray arrayWithObjects:vc1, vc2, nil]];
        [self.window setRootViewController:tbc];

        return YES;
    }
4

2 に答える 2

2

このように設定画面のコードを書きます

設定 *vc2 = [[Settings alloc]init];

画面を設定するためのnibファイルはどこにありますか、

一度このようにしてみてください

UITabBarController *tbc = [[UITabBarController alloc]init];

ViewController *vc1 = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
Settings *vc2 = [[Settings alloc]initWithNibName:@"Settings" bundle:nil];

[vc1.tabBarItem setTitle:@"Browse"];
[vc2.tabBarItem setTitle:@"Settings"];

[tbc setViewControllers:[NSArray arrayWithObjects:vc1, vc2, nil]];
[self.window setRootViewController:tbc];
[self.window makeKeyAndVisible];
于 2013-09-14T14:32:40.943 に答える
1

試してみてください:

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

    UITabBarController *tbc = [[UITabBarController alloc]init];

    ViewController *vc1 = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
    Settings *vc2 = [[Settings alloc]init];

    [vc1.tabBarItem setTitle:@"Browse"];
    [vc2.tabBarItem setTitle:@"Settings"];

    [tbc setViewControllers:[NSArray arrayWithObjects:vc1, vc2, nil]];
    [self.window setRootViewController:tbc];
    [self.window makeKeyAndVisible];

    return YES;
}
于 2013-09-14T14:26:23.110 に答える