ダッシュボード用と登録用の 2 つの異なるビュー コントローラーがあります。ユーザーがアラートビューからログインするまで、ユーザーがダッシュボードで何かを操作できるようにしたくありません。そのため、ユーザーがダッシュボードに戻るか、キャンセルを押してログインしていないたびに、ログインアラートをポップアップさせたい.
これは、ユーザーが登録ビューのナビゲーション バーの戻るボタンを押した場合を含め、すべての場合で完全に機能しますが、ユーザーが登録ページのアラートで [OK] をクリックした場合は機能しません。
ダッシュボード ビューには次のコードが含まれます。
@property(strong) UIAlertView * alert;
//...
-(void)viewWillAppear:(BOOL)animated
{
user_email = [[NSUserDefaults standardUserDefaults] stringForKey:@"email"];
if ( user_email==nil ){
[self auto_login];
} else //...
}
-(void)auto_login
{
alert = [[UIAlertView alloc] initWithTitle:@"Login" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Login",@"Forgot Password",@"Register",nil];
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
{
self.debug.text = @"Cancel";
[self auto_login];
break;
}
//...
default:
{
self.debug.text = @"Register";
[self nav_register];
break;
}
}
}
-(void)nav_register
{
RegisterProfileController *rvc = [[RegisterProfileController alloc] init];
[self.navigationController pushViewController:rvc animated:YES];
}
登録ビュー コントローラーには、次のコードが含まれています。
-(void)catch_registration
{
NSString *response = [[NSString alloc] initWithData:self.httpdata encoding:NSASCIIStringEncoding];
if( [response isEqualToString:@"OK"] ){
UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"..." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
successAlert.alertViewStyle = UIAlertViewStyleDefault;
[successAlert show];
}
else //...
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if ([alertView.title isEqualToString:@"Success"])
[self.navigationController popViewControllerAnimated:TRUE];
}
clickedButtonAtIndex
デバッグ後、登録View Controllerで[alert show]
実行した後、Dashboard View Controllerで実行し、Dashboard View Controllerで実行しないことがわかりましclickedButtonAtIndex
たが、アラートは表示されません。
アラートが表示されないのはなぜですか、またはこれをさらにデバッグするにはどうすればよいですか?