如何在ViewController已有委托时设置委托?

时间:2012-10-31 21:48:01

标签: ios uiviewcontroller uialertview

我有一个发送电子邮件的iPhone应用程序。如果未设置“收件人:”地址,则显示警报(UIAlertView)。目前,我没有检查用户点击确定,我只是继续我的快乐方式! :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>  {

如何设置委托以便处理“确定”按钮,从而删除错误?

2 个答案:

答案 0 :(得分:4)

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

@interface ReportViewController : UIViewController <UIWebViewDelegate, UIAlertViewDelegate>  {

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

答案 1 :(得分:1)

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