【问题标题】:Delegate Method failing to call when tested with If statement, but calls correctly without If statement使用 If 语句测试时委托方法调用失败,但在没有 If 语句的情况下正确调用
【发布时间】:2013-08-09 20:57:36
【问题描述】:

我有这个 if 语句检查我的委托是否实现了给定的方法:

    if ([[self delegate] respondsToSelector:@selector(didFinishSettingNotificationOnDialog:)])
{
        [self.delegate didFinishSettingNotificationOnDialog:self withNotification:notification];

}

但是我的代码没有在 If 语句中执行。如果我删除 if 语句并只调用

,我还有其他委托调用在这些对象之间工作
[self.delegate didFinishSettingNotificationOnDialog:self withNotification:notification];

它本身就可以工作!

我的委托确实正确实施:

- (void)didFinishSettingNotificationOnDialog:(NotificationDialogView *)dialogView withNotification:(NotificationContext *)setNotification{
    NSLog(@"Notification is: %@", setNotification);
}

那我做错了什么?

【问题讨论】:

    标签: ios objective-c cocoa-touch delegates uikit


    【解决方案1】:

    方法名称错误。应该是didFinishSettingNotificationOnDialog:withNotification:

    试试这个:

     if ([[self delegate] respondsToSelector:@selector(didFinishSettingNotificationOnDialog:withNotification:)]) {
        [self.delegate didFinishSettingNotificationOnDialog:self withNotification:notification];
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-19
      • 1970-01-01
      • 2013-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-13
      • 1970-01-01
      相关资源
      最近更新 更多