結果を Web サービスで使用するための小さなアプリを作成しています。結果は SplitViewController に表示され、左側に結果、右側に詳細が表示されます。結果を取得する前に、アプリを起動するたびに最初に表示されるログイン画面からログインするようにユーザーに依頼します。
ログインが成功した後、アプリケーションの RootViewController を変更して、ログイン プロセスを管理しました。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"LoginControllerSeque"] && [self doLogin]){
TMAppDelegate *appDelegate = (TMAppDelegate *)[[UIApplication sharedApplication]delegate];
// IPad
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UISplitViewController *cvc = (UISplitViewController *)[segue destinationViewController];
[appDelegate.window setRootViewController:cvc];
}
// Other device
else {
UINavigationController *cvc = (UINavigationController *)[segue destinationViewController];
[appDelegate.window setRootViewController:cvc];
}
[appDelegate switchToMainView];
}
else{
alertView = [[UIAlertView alloc] initWithTitle:@"access denied" message:@"access denied" delegate:self cancelButtonTitle:@"back" otherButtonTitles:nil];
[alertView show];
}
SplitViewController に切り替えるために Storyboard セグエを使用していますが、それ以上のアクションがなければ何もしません。
私の AppDelegate には、次の部分があります。
- (void)switchToMainView{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
UINavigationController *masterNavigationController = [splitViewController.viewControllers objectAtIndex:0];
TMMasterViewController *controller = (TMMasterViewController *)masterNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
} else {
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
TMMasterViewController *controller = (TMMasterViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
}
[self.window reloadInputViews];
[self.window makeKeyAndVisible];}
これまでのところすべてが機能していますが、ログイン画面に続くSplitViewのdetailViewControllerのPopoverViewにログアウトボタンがあります。同じようにできると思ったので、次のようにしました。
- (IBAction)logout:(id)sender {
[self.currentPopover dismissPopoverAnimated:NO];
TMAppDelegate *appDelegate = (TMAppDelegate *)[[UIApplication sharedApplication]delegate];
[appDelegate.window setRootViewController:[appDelegate loginViewController]];
[appDelegate switchToLoginView];
}
そしてAppDelegateで:
- (void)switchToLoginView
{
[self.window reloadInputViews];
[self.window makeKeyAndVisible];
}
2 回目にログインしようとすると、次のエラーが表示されます。
なぜこれが初めて機能し、2回目にこれらの問題が発生するのか、私にはわかりません。
誰かが私を助けたり、ヒントをくれたりできますか? ログイン処理の概念が間違っているのではないでしょうか?
アップデート:
問題はまさにこの部分に現れます:
// Beim IPad müssen wir uns anders verhalten als beim Phone
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
UISplitViewController *cvc = (UISplitViewController *)[segue destinationViewController];
[appDelegate.window setRootViewController:cvc];
}
Line: [appDelegate.window setRootViewController:cvc];に入ります。