我有两个不同的视图控制器,一个用于仪表板,一个用于注册。在用户通过警报视图登录之前,我不希望用户能够与仪表板上的任何内容进行交互。因此,每次用户导航回仪表板或按下取消并且他们没有登录时,我都希望弹出登录警报。
这在所有情况下都能完美运行,包括当用户在注册视图中点击导航栏上的后退按钮时,但当用户在注册页面的警报上单击“确定”时不起作用。
仪表板视图包含以下代码:
@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
在注册视图控制器中[alert show]
运行后,在仪表板视图控制器clickedButtonAtIndex
中运行,并且不在仪表板视图控制器中运行,但没有显示警报。
为什么不显示警报或如何进一步调试?