2011-08-10 8 views
0

ユーザーが「otherbutton」をタップすると、それは自分のリンクに移動します。 しかし、一度ボタンを押すと、何もしません。私のiPhone上UIAlertView。 openURLとしてotherbuttonを使用しています。

申し訳ありませんイムので、私はコード

http://pastebin.com/fvgk87ih

用ペーストビンを使用しましたあなたのUIAlertViewdelegateがクラス(ほとんどの場合、self)に設定する必要があります

答えて

1

コントローラクラスをUIAlertViewDelegateプロトコルに準拠させます。

@interface MyViewController : UIViewController <UIAlertViewDelegate> 

自己に設定デリゲートでアラートビューを作成します(!buttonIndex = [alertView cancelButtonIndex])場合は、デリゲートメソッド

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { 
    if (buttonIndex != [alertView cancelButtonIndex]) { 
     // open url 
    } 
} 
+0

ありがとうございました。 – Laaaa

1

たくさん感謝それはそれを使用しています。 UIAlertViewを呼び出すクラスがUIAlertViewDelegateデリゲートに準拠していることを確認してください。

1

UIAlertViewdelegateプロパティをnilの代わりにselfに設定し、ヘッダーにプロトコルを実装する必要があります。

ヘッダーファイル:

@interface MyViewController : UIViewController <UIAlertViewDelegate> 

はまた、buttonIndexをチェック。現在、(上記を実行した後に)のいずれかのボタンを押すとURLが開きます。

- (void)alertView: (UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex 
{ 
    if (buttonIndex != [alertView cancelButtonIndex]) 
    { 
     //open url 
    } 
} 
+0

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Follow" message:@"me on twitter" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; [alert show]; [alert release]; 

応答しはする必要があります! –

関連する問題