0

ポップアップ アラートの表示を練習するためだけに非常に単純な iOS アプリケーションを実装していますが、アラート ボタンを押すとエラーが発生します。

スレッド 1:EXC_BAD_ACCESS(コード=1、アドレス=0x676f6f57)

これはコードです:

- (IBAction)AlertButton {


    alert = [[UIAlertView alloc]
         initWithTitle:@"Alert" message:@"Alert"
         delegate:self
         cancelButtonTitle:@"Dismiss"
         otherButtonTitles:@"Apple", "Google" ,nil];
    [alert show];}


-(void)alertView :(UIAlertView *)alertView clickedButttonAtIndex:(NSInteger)buttonIndex{

    if(buttonIndex == 1){
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://apple.com"]];
    }
    if(buttonIndex == 2){
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://google.com"]];
    }}
4

2 に答える 2

4

UIAlertView問題は、行の , のコンストラクタにあります。

otherButtonTitles:@"Apple", "Google" ,nil];

@あなたの前を忘れてください"Google"。そして最後に変更します:

-(void)alertView :(UIAlertView *)alertView clickedButttonAtIndex:(NSInteger)buttonIndex{

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
于 2013-02-21T19:57:01.037 に答える
1

本当の問題は@、 の前に"Google"がないため、 ではなく、NSStringしたがってクラッシュすることです。

この .h を使用します

IBOutlet.justは必要ありません

 UIAlertView *alert;

.m

alert = [[UIAlertView alloc]
        initWithTitle:@"Alert"
              message:@"Alert"
             delegate:self
    cancelButtonTitle:@"Dismiss"
    otherButtonTitles:@"Apple", @"Google", nil
];
于 2013-02-21T19:52:25.353 に答える