使用TabBarCtrl的UITabBarController UIViewController视图不会出现在我的ViewCtrl中:(

时间:2009-08-31 17:07:23

标签: iphone uiviewcontroller uitabbarcontroller

我有UITabBarController视图管理的 MainController 类。

当我尝试从ViewController显示我的TabBarController时 - 它显示清晰的屏幕。 :-(我只能从__AppDelegate显示我的TabBarController。=)

如何从基于UIViewController的视图中显示TabBarController? =)

请帮帮我们。非常感谢。 =)

// MainController.h

@interface MainController : UIViewController {
    IBOutlet UITabBarController * tabBarController;
}
@property (nonatomic, retain) IBOutlet UITabBarController * tabBarController;
@end

我有MyTestAppDelegate:

// MyTestAppDelegate.h

#import "MainController.h"    

@class MainController;

@interface MyTestAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    MainController * mController;
    IBOutlet UIViewController * viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) MainController * mController;
@property (nonatomic, retain) IBOutlet UIViewController * viewController;

@end

// MyTestAppDelegate.m

#import "MyTestAppDelegate.h"
@implementation MyTestAppDelegate

@synthesize window, mController, viewController;


- (void)applicationDidFinishLaunching:(UIApplication *)application {
    MainController * mc = [[MainController alloc] initWithNibName:@"MainView" bundle:nil];
    self.mController = mc;      
    [mc release];

    [window addSubview:[self.viewController view]];

    [[viewController view] addSubview:[mController.tabBarController view]];

    [window makeKeyAndVisible];
}
@end

1 个答案:

答案 0 :(得分:0)

文档说UITabBarController必须在根级别。请参阅此处的链接和可能的解决方法:http://discussions.apple.com/thread.jspa?threadID=2190703&tstart=0

我已根据上述帖子的代码http://discussions.apple.com/thread.jspa?messageID=10708521&#10708521

在此处发布了包含工作代码的完整项目