我正在尝试将数据从子类发送到父类。实现我的自定义委托(delegate)后,我收到此错误:
Cannot find protocol declaration for 'SLBPostViewControllerDelegate'
这是我的代码:
child.h
@protocol SLBPostViewControllerDelegate <NSObject>
- (void)dataToBeUploaded:(PFFile *)data;
@end
@interface
@property (weak, nonatomic) id <SLBPostViewControllerDelegate> delegate;
@end
child.m
[self.delegate dataToBeUploaded:image];
parent.h
@interface SLBWallViewController : UIViewController <SLBPostViewControllerDelegate>
parent.m
- (void)dataToBeUploaded:(PFFile *)data{
NSLog(@"%@", data);
}
我的错误在哪里?我该如何解决?
最佳答案
parent.h
需要#import child.h
才能了解协议(protocol)声明。
如果您正在导入它但仍然出现错误,则可能存在循环导入。在这种情况下,在 @interface
之上的 parent.h
中转发声明协议(protocol),例如
@protocol SLBPostViewControllerDelegate;
@interface SLBWallViewController : UIViewController <SLBPostViewControllerDelegate>
...
@end
关于ios - 从子类到父类的自定义委托(delegate)(subview-superview),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17601761/