iphone-将子视图添加到窗口后无法推送模式视图?
Im我的应用程序我有以下代码,第一位在我的应用程序启动时运行,它在模式视图中显示一个登录屏幕。在此之前,我的rootController被添加到了窗口中 模式视图将允许用户登录、查看条款和条件,然后如果用户接受loadMainApp功能,则调用该功能iphone-将子视图添加到窗口后无法推送模式视图?,iphone,ios,uinavigationcontroller,presentmodalviewcontroller,abpeoplepickerview,Iphone,Ios,Uinavigationcontroller,Presentmodalviewcontroller,Abpeoplepickerview,Im我的应用程序我有以下代码,第一位在我的应用程序启动时运行,它在模式视图中显示一个登录屏幕。在此之前,我的rootController被添加到了窗口中 模式视图将允许用户登录、查看条款和条件,然后如果用户接受loadMainApp功能,则调用该功能 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Overri
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
rootController.delegate = self;
[window addSubview:rootController.view];
LoginViewController *_loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:[NSBundle mainBundle]];
self.loginViewController = _loginViewController;
[_loginViewController release];
UINavigationController *navi = [[[UINavigationController alloc]initWithRootViewController:loginViewController]autorelease];
navi.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[loginViewController release];
[rootController presentModalViewController:navi animated:YES];
[self.window makeKeyAndVisible];
return YES;
}
当用户接受条款和条件时,调用下一位:
-(void)loadMainApp:(UIView *)fromView{
[fromView removeFromSuperview];
[window addSubview:rootController.view];
rootController.selectedIndex = 2;
rootController.delegate = self;
}
在这里,我希望能够使用people picker,这是一个模态视图,我尝试使用以下代码:
ABPeoplePickerNavigationController *picker =
[[ABPeoplePickerNavigationController alloc]init];
picker.peoplePickerDelegate = self;
[rootController presentModalViewController:picker animated:YES];
[picker release];
但是什么也没有发生,当我试图从我的rootController呈现一个模态视图时,什么也没有显示
这似乎是在ApplicationIDFinishLaunching中的此代码运行后发生的:
LoginViewController *_loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:[NSBundle mainBundle]];
self.loginViewController = _loginViewController;
[_loginViewController release];
UINavigationController *navi = [[[UINavigationController alloc]initWithRootViewController:loginViewController]autorelease];
navi.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[loginViewController release];
[rootController presentModalViewController:navi animated:YES];
[self.window makeKeyAndVisible];
return YES;
如果我根本不显示登录屏幕,而是添加我的rootController
rootController.delegate = self;
[window addSubview:rootController.view];
在ApplicationIDFinishLaunching函数中,当我显示人员选择器时,一切正常
是否有一些基本的东西我在这里打破了,或者任何人都能发现我可能做错了什么?您是否通过
dismissModalViewControllerAnimated:
方法正确地解除了第一个模态视图控制器?如果您只是将模态视图控制器的视图从其superview中删除,那么UIKit可能没有完成大量的文书工作。您真正应该做的是:
在AppDelegate中:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Make sure rootViewController is initiated by this point.
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];
[window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
在RootViewController中:
- (void)viewDidLoad {
[super viewDidLoad];
LoginViewController *loginViewController = [[[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil] autorelease];
loginViewController.delegate = self;
loginViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:loginViewController animated:YES];
}
- (void)loginViewControllerFinished {
[self dismissModalViewControllerAnimated:YES];
// Here we are closing one modal. And showing another after that.
ABPeoplePickerNavigationController *peoplePicker = [[[ABPeoplePickerNavigationController alloc] init] autorelease];
peoplePicker.peoplePickerDelegate = self;
[self presentModalViewController:peoplePicker animated:YES];
}
// Make sure LoginViewController has delegate property in header.
// @property (nonatomic, assign) id delegate;
// And put this in implementation (.m) file. @synthesize delegate.
// Don't put release for delegate, since it's not retained. It's only 'assigned'.
- (void)done {
// Call this when you want to close loginViewController.
[delegate loginViewControllerFinished];
}
在LoginViewController中:
- (void)viewDidLoad {
[super viewDidLoad];
LoginViewController *loginViewController = [[[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil] autorelease];
loginViewController.delegate = self;
loginViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:loginViewController animated:YES];
}
- (void)loginViewControllerFinished {
[self dismissModalViewControllerAnimated:YES];
// Here we are closing one modal. And showing another after that.
ABPeoplePickerNavigationController *peoplePicker = [[[ABPeoplePickerNavigationController alloc] init] autorelease];
peoplePicker.peoplePickerDelegate = self;
[self presentModalViewController:peoplePicker animated:YES];
}
// Make sure LoginViewController has delegate property in header.
// @property (nonatomic, assign) id delegate;
// And put this in implementation (.m) file. @synthesize delegate.
// Don't put release for delegate, since it's not retained. It's only 'assigned'.
- (void)done {
// Call this when you want to close loginViewController.
[delegate loginViewControllerFinished];
}
希望这有帮助