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

首先,似乎没有设置 self.viewController 属性,并且您正在实例化相同的“ViewController”两次。这都是错误的:

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 回答
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 回答