我有这个 if 语句来检查我的委托(delegate)是否已经实现了给定的方法:
if ([[self delegate] respondsToSelector:@selector(didFinishSettingNotificationOnDialog:)])
{
[self.delegate didFinishSettingNotificationOnDialog:self withNotification:notification];
}
但是我的代码没有在 If 语句中执行。如果我删除 if 语句并只调用
,我还有其他委托(delegate)调用在这些对象 和 之间工作[self.delegate didFinishSettingNotificationOnDialog:self withNotification:notification];
它本身就有效!
我的委托(delegate)确实正确实现了:
- (void)didFinishSettingNotificationOnDialog:(NotificationDialogView *)dialogView withNotification:(NotificationContext *)setNotification{
NSLog(@"Notification is: %@", setNotification);
}
那我做错了什么?
最佳答案
方法名错误。它应该是 didFinishSettingNotificationOnDialog:withNotification:
。
试试这个:
if ([[self delegate] respondsToSelector:@selector(didFinishSettingNotificationOnDialog:withNotification:)]) {
[self.delegate didFinishSettingNotificationOnDialog:self withNotification:notification];
}
关于ios - 委托(delegate)方法在使用 If 语句测试时调用失败,但在没有 If 语句的情况下正确调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18155549/