-3
-(void)otherGames
{
    UIAlertView *alertMsg = [[UIAlertView alloc]
    initWithTitle:@"This gGame was Developed By:"
    message:@"Burhan uddin Raizada"
    delegate:nil
    cancelButtonTitle:@"Dismiss"
    otherButtonTitles: @"@twitter" , nil];
    [alertMsg show];

}

-(void)alertMsg:(UIAlertView *)alertMsg clickedButtonAtIndex:(NSInteger)buttonIn… {

    if (buttonIndex == 1) {
        NSString *containingURL = [[NSString alloc] initWithFormat:@"http://www.twitter.com/…
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString: containingURL]];
    }
}

第一个 alertmsg 工作得很好。但是当我在新的“@twitter”按钮上添加了一个赞时,它就不起作用了。否则一切正常。我想知道为什么它没有,但它应该..需要帮助。

4

2 回答 2

-1

假如说

- (void)alertMsg:(UIAlertView *)alertMsg clickedButtonAtIndex:(NSInteger)buttonIn…

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

您必须将委托设置为self并将委托协议添加到您的标头:

@interface yourView : UIViewController <UIAlertViewDelegate>

编辑:根据@holex,使用alertView:willDismissWithButtonIndex:而不是 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

于 2012-08-07T13:58:49.680 回答
-2

更新

这个答案已经过时,因为UIAlertView在 iOS8 中已弃用。

UIAlertController您可以在 Apple 的 Dev Docs 上阅读更多信息。


第一的:

你还没有委派你的班级,delegate:nil表明没有UIAlertView. 您应该按照以下方式更正您的方法:

-(void)otherGames
{
    UIAlertView *alertMsg = [[UIAlertView alloc]
    initWithTitle:@"This gGame was Developed By:"
    message:@"Burhan uddin Raizada"
    // delegate:nil
    delegate:self // don't forget to implement the UIAlertViewDelegate protocol in your class header
    cancelButtonTitle:@"Dismiss"
    otherButtonTitles: @"@twitter" , nil];
    [alertMsg show];

}

第二:

回调方法的正确名称是:-alertView:didDismissWithButtonIndex:

//-(void)alertMsg:(UIAlertView *)alertMsg clickedButtonAtIndex:(NSInteger)buttonIn… { // WRONG, where have you got this silly idea...?
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        NSString *containingURL = [[NSString alloc] initWithFormat:@"http://www.twitter.com/…
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString: containingURL]];
    }
}

现在,您知道为什么您的代码片段是错误的了。

于 2012-08-08T08:03:58.670 回答