首页 > 解决方案 > 使用 UIAlertController 调用其包含函数

问题描述

Reachability用来检查 wifi 连接是否有任何变化。这将根据连接将变量wifiStatus设置为 Y 或 N。这工作正常。

当应用程序启动时,我有一个setup调用自身的函数,直到 wifiStatus 为 Y。

- (void)setup {
    if([wifiStatus isEqualToString:@"Y"]) {
        //go to another function;
    }
    else {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Wifi" message:@"You must be connected to the internet to complete set up." preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"Try again" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
            [self setup];
        }];
        [alert addAction:alertAction];
        [self presentViewController:alert animated:YES completion:nil];
    }
}

它工作得很好我只是检查如果用户必须按Try again多次我不会遇到任何类型的递归问题。

标签: objective-c

解决方案


推荐阅读