-1

iOS アプリでダイアログ ボックスを作成しようとしています (アプリは PhoneGap アプリケーションです)。

この投稿のコードを使用しています: iOS でポップアップ ダイアログ ボックスを実装する方法

以下はリンクにあるコードです

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No network connection" 
                                                message:@"You must be connected to the internet to use this app."
                                               delegate:nil 
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:nil];
[alert show];

このコードをAppDelegate.mメソッドに入れました

- (BOOL)application:(UIApplication)...

アプリは実行されますが、ダイアログ ボックスが表示されません。

何が問題ですか?


以下のようにコードを更新しました

以下のコードは私の appdelegate.m にあります

//reachability code

if (networkStatus == ReachableViaWifi)
{
    while (true)
        //show progress bar
}
else
{
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:@"cancel", nil];
    [alert show];
}

アラート ボックスが表示されません。私は何を間違っていますか?

4

4 に答える 4

0

iOS アラート ダイアログの場合、AppDelegate.m で

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No network connection" 
                                          message:@"You must be connected to the internet to use this app."
                                          delegate:nil 
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
[alert show];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
[self.window makeKeyAndVisible];
return YES;
}

phonegap を使用していると述べたので、さまざまなプラットフォームでアラート ボックスを処理します。ページの html の 1 つで次のコードを使用します。

function showAlert() {
    navigator.notification.alert(
        'You must be connected to the internet to use this app.',
        null,       
        'No network connection',            
        'OK'                  
    );
}
于 2013-04-24T22:00:37.727 に答える
0

コードを MainViewController.m (または他の UIViewController .m ファイル) に追加する必要があります。また、コードを追加する動作-(void)viewDidLoad-(void)viewDidAppearメソッドに応じて変更する必要があります。

于 2013-04-24T21:51:23.887 に答える