以下代码有什么问题?当alertView中的文本不为空时,我将更改viewController。问题是,每次都会改变UiViewController
,即使它是空的。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
if ([[alertView textFieldAtIndex:0].text isEqual:@""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error warning" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
else{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"ChangeView"];
[self presentViewController:vc animated:YES completion:nil];
}
}
}
答案 0 :(得分:1)
您应该执行此检查:
if (![[alertView textFieldAtIndex:0].text.length) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error warning" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
} else ...