我想在应用程序的开头显示模态视图,但它不会出现。这是我的代码:
- (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;
}
我该如何解决?
答案 0 :(得分: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与其第一个选项卡的视图控制器一起加载。
答案 1 :(得分:1)
从模型视图中启动一个instanse,如下所示:
modelView = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
请按照以下列表:
设置viewController模型呈现的样式
[modelView setModalPresentationStyle:UIModalPresentationPageSheet];
然后使用:
呈现它[self.viewController presentModalViewController:floorView animated:YES];
然后,设置模型控制器的大小和位置,如下所示:
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.
希望这对你有所帮助。