1

私はobjective-cの初心者で、次のような関数内にあるUIAlertを持っています:

- (void)loadJSON
{

    Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
    NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
    if (networkStatus == NotReachable) {
        dispatch_async(dispatch_get_main_queue(), ^{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Announcement" message: @"No Connection" delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release];
        });
    } else {
      //some code
    }
}

ユーザーが [OK] ボタンをクリックすると、この関数が起動して loadJSON 関数を呼び出す必要がありますか? (少なくとも私はそう思う)

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    [self loadJSON];
}

ここでの私の最終的な目標は、インターネットに接続されていない場合に UIAlert を表示し、ユーザーにメッセージが表示され、[OK] をクリックし、インターネットに接続されていない場合はアラートを表示することです。インターネットから切断しましたが、アラート メッセージが 1 回しか表示されません。

私のコードに何か問題がありますか?

4

1 に答える 1