2

我有一个发送电子邮件的 iPhone 应用程序。如果未设置“收件人:”地址,我将显示警报 (UIAlertView)。目前,我不检查用户是否点击 OK,我只是继续我的快乐方式!:D

在警报上点击确定时出现以下错误:

wait_fences:未能收到回复:10004003

我相信这是因为我没有处理 OK 的点击,并且当应用程序正在执行其他操作时它仍然显示。因此,在对 SO 和 Google 进行了一些研究之后,看来我必须拥有这个:

- (void) Alert: (NSString *) title andData: (NSString *) errorMsg  {

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle: title
                          message: errorMsg 
                          delegate:nil
                          cancelButtonTitle: @"OK"
                          otherButtonTitles: nil];
    [alert show];


    return;

}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"button was pressed");
}

我的问题是我不知道如何为此设置委托。我已经有一个代表:

@interface ReportViewController : UIViewController <UIWebViewDelegate>  {

如何设置委托以便处理 OK 按钮的点击,从而消除错误?

4

2 回答 2

4

在尖括号内,您可以提供以逗号分隔的协议列表。

@interface ReportViewController : UIViewController <UIWebViewDelegate, UIAlertViewDelegate>  {

现在您可以实现两组方法。并且不要忘记将警报视图的委托设置为self.

于 2012-10-31T21:52:56.413 回答
1

根据您在问题中的代码,您的代表看起来像 nil 'delegate:nil'。您需要将其更改为'delegate:self'.

于 2012-10-31T23:40:33.617 回答