2

UIAlertView のデリゲート メソッドをプログラムで呼び出そうとしています。コードは次のとおりです。

if([vc respondsToSelector:@selector(alertView:clickedButtonAtIndex:)]) {
        // Manually invoke the alert view button handler
        [(id <UIAlertViewDelegate>)vc alertView:nil
                           clickedButtonAtIndex:0];
    }

iOS5.0 では正常に動作しますが、iOS6.0 では動作しません。コメントや提案は大歓迎です :)

詳細の完全な方法は次のとおりです。

TWTweetComposeViewController *vc = [[[TWTweetComposeViewController alloc] init]autorelease];
    // Settin The Initial Text
    [vc setInitialText:status];
    [vc setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
        if(result == TWTweetComposeViewControllerResultDone) {

            NSLog(@"Tweeted Sucessfully");
            }
    }];
    if([delegate isKindOfClass:[UIViewController class]]){
        [(UIViewController *)delegate presentModalViewController:vc animated:YES];
    }
      //alertView:clickedButtonAtIndex:
    if([vc respondsToSelector:@selector(alertView:clickedButtonAtIndex:)]) {
        // Manually invoke the alert view button handler
        [(id <UIAlertViewDelegate>)vc alertView:nil
                           clickedButtonAtIndex:0];
    }
}
4

5 に答える 5

2

あなたのコードでは、次のようなアラートビューオブジェクト名をアラートビューに指定するだけです..

[(id <UIAlertViewDelegate>)vc alertView:yourAlertView
                           clickedButtonAtIndex:0];

それ以外の場合は、次のコードを試してください..

   id<UIAlertViewDelegate> delegate = yourAlertView.delegate;
    yourAlertView.delegate = nil;
    [delegate alertView:yourAlertView clickedButtonAtIndex:0];

それに関する他のオプションについては、このリンクを参照してください..

なぜ-doesnt-dismisswithclickedbuttonindex-ever-call-clickedbuttonatindex

于 2013-02-19T05:54:12.560 に答える
2

デリゲート メソッドを直接呼び出すのは悪い習慣です。UIAlertViewと呼ばれるメソッドがありdismissWithClickedButtonIndex:animated:ます。それを呼び出すと、デリゲートが正しく設定されていると仮定して、UIAlertViewDelegateメソッドalertView:willDismissWithButtonIndex:と が呼び出されます。alertView:didDismissWithButtonIndex:

于 2013-02-19T06:01:24.763 に答える
1

There are no such differences regarding implementation of Alert view in iOS 6. You can complete your task easily by using this delegate method - :

(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;  

try this and after that let us know what kind of warning you get in console...

于 2013-02-19T06:05:43.190 に答える
1

このデリゲートを使用できます。これはうまくいきます..

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;  
于 2013-02-19T05:48:08.077 に答える
0

TWTeetComposeViewController は IOS6 で非推奨になりました。代わりに DETweet をお試しください。:) iOS 6 でも問題なく動作します。:)

于 2013-02-19T08:39:44.743 に答える