2012-09-02 56 views
1

我有一个tabBarView和一个GWDNativeViewController。 GWDNativeViewController是一个主菜单。我试图让该视图首先显示并超过tabBarView。我在IBAction中设置了相同的代码,它可以工作。当我将它放入Loaddidfinishwithoptions时,它不起作用。iOS - 第二视图不显示在选项卡视图上

@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]; 

} 
+0

secondView是否有视图?你说这不起作用 - 你看到了什么? – rdelmar

+0

我刚刚编辑帖子以包含工作代码。当简单地放置在viewDidLoad中时,除了显示tabBarController外,它什么也不做。然而,当用作IBAction时,相同的代码有效。 – temmanuel

回答

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行。

+0

这是问题所在。谢谢! – temmanuel

0

tabBarController的视图尚未载入此处。你可以在5个视图控制器中的一个中将该代码放入viewDidLoad中。

+0

谢谢你的回应。这是一个很好的想法。我试图把它放在那里(清理和重建),但它没有让它出现。 – temmanuel

+0

你还在试图从你的标签栏中显示它吗?你应该从其viewDidLoad所在的视图控制器中呈现它。这应该起作用。 – thejav

相关问题