UiAlertView 应该改变 ViewController

UiAlertView should change ViewController

以下代码有什么问题?当 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];
        }
    }
}

您应该改为执行此检查:

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 ...