Tôi sẽ đánh giá cao nếu có ai có thể giải thích logic đằng sau sự thừa kế giao thức. ví dụ. ý nghĩa sau đây là gì (UITableView.h):Hiểu về sự thừa kế giao thức trong mục tiêu-C
@protocol UITableViewDelegate<NSObject, UIScrollViewDelegate>
Việc triển khai lớp sau không hoạt động. Tôi có một lớp View1 (kế thừa UIView), với một giao thức liên quan. Tôi có một lớp khác, View2 (trong đó hít vào View1). Bây giờ tôi muốn kế thừa giao thức là tốt. Bất cứ ai có thể xin vui lòng chỉ cho tôi đi đúng hướng.
Lớp 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
Lớp 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
Cảm ơn bạn đã trả lời của bạn. Tôi tuyên bố giao thức như bạn đã đề cập, nhưng vấn đề tôi đang phải đối mặt là với tuyên bố của id <...> đại biểu; Trong View1, tôi có id delegate; với liên kết @property và @synthesize. Vì tôi đang kế thừa View1 trong View2, khi tôi khai báo id delagete; với nó được liên kết @property và @synthesize, tôi nhận được một lỗi: "Thuộc tính 'đại biểu' cố gắng sử dụng ivar 'đại biểu' tuyên bố trong lớp siêu của 'View2'. Cách chính xác để xử lý tình huống này là gì. đã đăng ở trên. –
Mustafa