0

アプリの起動時にモーダルビューを表示したいのですが、表示されません。これは私のコードです:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self initDataBase];
    CustomerModel *customer = [[[CustomerPersistor alloc] init] getLoggedCustomer];

    self.window.rootViewController = self.tabBarController;

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.

    UIViewController *profileViewController = [[[ProfileViewController alloc] initWithNibName:@"ProfileViewController" bundle:nil] autorelease];
    profileViewController.title = @"Profile";
    UINavigationController *profileNavigation = [[[UINavigationController alloc] initWithRootViewController:profileViewController] autorelease];

    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:profileNavigation,  nil];
    self.window.rootViewController = self.tabBarController;

    [self.window makeKeyAndVisible];

    if(customer == nil) { NSLog(@"HO");
        ViewController *login = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    //login.delegate = self.tabBarController.view;

        [self.viewController presentModalViewController:[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]  animated:YES];
    }
    return YES;

}

どうすれば修正できますか?

4

2 に答える 2

1

次のように、モデル ビューからインスタンスを開始します。

modelView = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

以下のリストに従ってください。

  1. viewController モデルの提示スタイルを設定する

    [modelView setModalPresentationStyle:UIModalPresentationPageSheet];
    
  2. 次に、次を使用して提示します。

    [self.viewController presentModalViewController:floorView animated:YES];
    
  3. 次に、モデル コントローラーのサイズと位置を次のように設定します。

    modelView.view.superview.bounds = CGRectMake(0, 0, 700, 550);//it's important to do this after presentModalViewController
    modelView.view.superview.center = self.view.superview.center;//self.view assumes the base view is doing the launching, if not you might need self.view.superview.center etc.
    

これがお役に立てば幸いです。

于 2012-08-22T12:49:16.830 に答える
1

まず、設定されている self.viewController プロパティがないように見え、同じ「ViewController」を 2 回インスタンス化しています。これはすべて間違っています:

ViewController *login = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 
//login.delegate = self.tabBarController.view;
[self.viewController presentModalViewController:[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]  animated:YES]; 

このコードを profileViewController の viewDidLoad に移動してみてください...つまり、TabBarController を最初のタブのビュー コントローラーと共にロードします。

于 2012-08-22T12:46:38.750 に答える