ios - 当 ViewController 已经有委托(delegate)时如何设置委托(delegate)?

标签 ios uiviewcontroller uialertview

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

点击警报上的“确定”时出现以下错误:

wait_fences: failed to receive reply: 10004003

我相信这是因为我没有处理“确定”的点击,并且当应用程序正在执行其他操作时它仍然显示。因此,在对 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");
}

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

@interface ReportViewController : UIViewController <UIWebViewDelegate>  {

如何设置委托(delegate)以便处理“确定”按钮的点击,从而消除错误?

最佳答案

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

@interface ReportViewController : UIViewController <UIWebViewDelegate, UIAlertViewDelegate>  {

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

关于ios - 当 ViewController 已经有委托(delegate)时如何设置委托(delegate)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13167932/

相关文章:

ios - 类别中的自定义 NSManagedObject setter

iOS UTF-8 标签字符串

ios - iOS 的 CI/Build 工具(例如 Bitrise.io)和 API key 的 plist 文件

ios - 某些 UIViewController 中的 XAMARIN.IOS UITabBarController

ios - 如何使用图像创建 UIAlertView

ios - 任何人都可以在 iOS 上使用 Swift SMART FHIR 吗?

ios - 关闭 viewController 总是触发 viewDidLoad 并且从不触发 viewWillAppear

ios - 我的 Storyboard 包含我的观点吗?

ios - 在不使用 segue 的情况下单击确定警报按钮后导航到另一个 View

ios - 如何在 iOS 中将 UIAlertView 显示为全屏?