【发布时间】:2010-09-20 13:27:42
【问题描述】:
如果有人能解释协议继承背后的逻辑,我将不胜感激。例如以下是什么意思(UITableView.h):
@protocol UITableViewDelegate<NSObject, UIScrollViewDelegate>
以下类实现不起作用。我有一个带有关联协议的类 View1(它继承 UIView)。我有另一个类,View2(继承 View1)。现在我也想继承协议。谁能指出我正确的方向。
第 1 类:
@protocol View1Delegate;
@interface View1 : UIView {
id <View1Delegate> delegate;
// . . .
}
@property (nonatomic, assign) id <View1Delegate> delegate; // default nil. weak reference
@end
@protocol View1Delegate <NSObject>
- (void)View1DelegateMethod;
@end
@implementation View1
@synthesize delegate;
// . . .
@end
第 2 类:
@protocol View2Delegate;
@interface View2 : View1 {
id <View2Delegate> delegate;
// . . .
}
@property (nonatomic, assign) id <View2Delegate> delegate; // default nil. weak reference
@end
@protocol View2Delegate <NSObject>
- (void)View2DelegateMethod;
@end
@implementation View2
@synthesize delegate;
// . . .
@end
【问题讨论】:
标签: iphone objective-c inheritance protocols