3

私はiPhoneアプリケーションにUITabBarControllerを追加しています。TabsAppDelegate.hでこのように言及しました。

#import <UIKit/UIKit.h>

@interface TabsAppDelegate : NSObject <UIApplicationDelegate,   UITabBarControllerDelegate> {
    UIWindow *window;
    UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;


@end

そして私のTabsAppDelegate.mdidFinishLaunchingWithOptionsメソッド

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions {    



    // Add the tab bar controller's view to the window and display.
    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];

    return YES;
}

MainWindow.xibに、タブバーコントローラーを追加し、tabBarControllerと接続します。その後、2つのViewControllerであるFirstViewControllerとSeconViewControllerを作成しました。最初のタブでFirstViewController.xibを追加し、2番目のタブでBuilderインターフェイスを使用してSecondViewController.xibファイルを追加しました。

しかし、プロジェクトを実行すると、黒い画面が表示されます。君の力が必要。前もって感謝します。

4

2 に答える 2

2
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {


        UIViewController *viewController1 = [[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil] autorelease];
                UINavigationController *navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
                navviewController1.title = @"FirstTitle";
        //        navviewController1.navigationBarHidden=YES;

        UIViewController *viewController2 = [[[yourviewController2 alloc] initWithNibName:@"yourviewController2" bundle:nil] autorelease];
                UINavigationController *navviewController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
        //        navviewController2.navigationBarHidden=YES;
                navviewController2.title = @"SecondTitle";

        UIViewController *viewController3 = [[[yourviewController3 alloc] initWithNibName:@"yourviewController2" bundle:nil] autorelease];
                UINavigationController *navviewController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
        //        navviewController3.navigationBarHidden=YES;
                navviewController3.title = @"ThirdTitle";

               //..... and so on depend on your requirement 

        self.tabBarController = [[[UITabBarController alloc] init] autorelease];
        self.tabBarController.viewControllers = [NSArray arrayWithObjects:navviewController1, navviewController2 , navviewController3 ,nil];
        self.window.rootViewController = self.tabBarController;
        [self.window makeKeyAndVisible];
    }

rootViewControllerを追加するのを忘れただけでこれを試してください

于 2012-10-18T09:21:23.340 に答える
0

「SignleView」テンプレートを使用してプロジェクトを作成しました。プログラムでtabBarViewCongtrollerに変換しました。その点に注意してください。たとえば、viewCongtroller.xibインスタンスを4回作成して、4つのタブで表示する場合にのみ、個別のviewControllerを追加できます。

これが私のコードで、iPhoneSimulater5.1でテストされています。

@implementation AppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;
@synthesize tb;
- (void)dealloc
{
    [_window release];
    [_viewController release];
    [tb release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSMutableArray *arr=[[NSMutableArray alloc]init];
    ViewController *vc1=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
    vc1.title=@"View1";
    vc1.tabBarItem=[[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1]autorelease];
    UINavigationController *nv1=[[UINavigationController alloc]initWithRootViewController:vc1];
    [arr addObject:nv1];
    [vc1 release];
    [nv1 release];

    ViewController *vc2=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
    vc2.title=@"View2";
    UINavigationController *nv2=[[UINavigationController alloc]initWithRootViewController:vc2];
    vc2.tabBarItem=[[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:2]autorelease];
    [arr addObject:nv2];
    [vc2 release];
    [nv2 release];

    ViewController *vc3=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
    vc3.title=@"View3";
    UINavigationController *nv3=[[UINavigationController alloc]initWithRootViewController:vc3];
    vc3.tabBarItem=[[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:3]autorelease];
    [arr addObject:nv3];
    [vc3 release];
    [nv3 release];

    ViewController *vc4=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
    vc4.title=@"View4";
    vc4.tabBarItem=[[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory tag:4]autorelease];
    UINavigationController *nv4=[[UINavigationController alloc]initWithRootViewController:vc4];
    [arr addObject:nv4];
    [vc4 release];
    [nv4 release];

    self.tb=[[[UITabBarController alloc]init]autorelease];
    tb.delegate=self;
    tb.viewControllers=arr;
    [arr release];
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
//    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    self.window.rootViewController = self.tb;

    [self.window makeKeyAndVisible];
    return YES;
}
于 2012-10-18T10:19:22.133 に答える