1

tabBarView と GWDNativeViewController があります。GWDNativeViewController はメイン メニューです。そのビューを最初に表示して、tabBarView の上に表示しようとしています。これと同じコードを IBAction 内に設定しましたが、動作します。Loaddidfinishwithoptions に入れると、機能しません。

@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 で機能しない理由はわかりませんが、[self.window makeKeyAndVisible] 行を secondView を定義する前に配置すると、applicationDidFinishLaunchingWithOptions: で機能します。

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

すぐに表示する場合は、animated オプションを NO に変更し、modalTransitionStyle を定義する行を削除します。

于 2012-09-02T04:40:18.797 に答える