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

in you code just give the alertview with your alertview obect name like bellow..

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

otherwise Just try with this bellow code..

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

see this link for some other option about it..

why-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

在 iOS 6 中 Alert 视图的实现没有这样的差异。您可以使用此委托方法轻松完成您的任务 - :

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

试试这个,然后让我们知道你在控制台中得到什么样的警告......

于 2013-02-19T06:05:43.190 回答
1

你可以使用这个委托,这对你有用..

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

IOS6 中不推荐使用 TTWeetComposeViewController。请尝试使用 DETweet。:) 在 iOS 6 上也可以正常工作。:)

于 2013-02-19T08:39:44.743 回答