1

我有一个 tabBarView 和一个 GWDNativeViewController。GWDNativeViewController 是一个主菜单。我试图让该视图首先显示并覆盖 tabBarView。我在 IBAction 中设置了相同的代码,并且可以正常工作。当我将它放入 Loaddifinishwithoptions 时,它不起作用。

@implementation GWDNativeAppDelegate
@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
@synthesize secondView = _secondView;

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

    // Override point for customization after application launch.
    UIViewController *viewController1 = [[GWDNativeFirstViewController alloc] initWithNibName:@"GWDNativeFirstViewController" bundle:nil];
    UIViewController *viewController2 = [[GWDNativeSecondViewController alloc] initWithNibName:@"GWDNativeSecondViewController" bundle:nil];
    UIViewController *viewController3 = [[GWDNativeThirdViewController alloc] initWithNibName:@"GWDNativeThirdViewController" bundle:nil];
    UIViewController *viewController4 = [[GWDNativeFourthViewController alloc] initWithNibName:@"GWDNativeFourthViewController" bundle:nil];
    UIViewController *viewController5 = [[GWDNativeFifthViewController alloc] initWithNibName:@"GWDNativeFifthViewController" bundle:nil];

    //tabBarController Stuff
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, viewController4, viewController5, nil];
    self.window.rootViewController = self.tabBarController;

    //Specify W`enter code here`hich tab to display (Number need to be set based on button selected)
    //self.tabBarController.selectedIndex = 2;       

    GWDNativeViewController *secondView = [[GWDNativeViewController alloc] initWithNibName:nil bundle:nil];
    [secondView setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self.tabBarController presentModalViewController:secondView animated:YES];

    [self.window makeKeyAndVisible];
    return YES;
}

这是 GWDNativeFirstViewController.m 中的代码 IBAction 中的代码有效。viewDidLoad 中的代码无效。?

-(IBAction)pressedButton {

    GWDNativeViewController *secondView = [[GWDNativeViewController alloc] initWithNibName:nil bundle:nil];
    [secondView setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self presentModalViewController:secondView animated:YES];
    //[secondView release];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"First", @"First");
        self.tabBarItem.image = [UIImage imageNamed:@"first"];

    }
    return self;
}

- (void)viewDidLoad
{
    [contentWebView1 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.web.org/?iapp=1#tab1"]]];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

     GWDNativeViewController *secondView = [[GWDNativeViewController alloc] initWithNibName:nil bundle:nil];
     [secondView setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
     [self.tabBarController presentModalViewController:secondView animated:YES];

}
4

2 回答 2

0

tabBarController 的视图还没有加载到这里。您可以将该代码放入 5 个视图控制器之一的 viewDidLoad 中。

于 2012-09-02T01:29:38.617 回答
0

我不确定为什么它在 viewDidLoad 中不起作用,但它可以在 applicationDidFinishLaunchingWithOptions 中起作用:如果您在定义 secondView 之前放置 [self.window makeKeyAndVisible] 行。

[self.window makeKeyAndVisible];
 GWDNativeViewController *secondView = [[GWDNativeViewController alloc] initWithNibName:nil bundle:nil];
 [secondView setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
 [self.tabBarController presentModalViewController:secondView animated:YES];

如果您希望它立即出现,请将动画选项更改为 NO,并删除定义 modalTransitionStyle 的行。

于 2012-09-02T04:40:18.797 回答