【发布时间】:2016-06-23 15:10:33
【问题描述】:
我创建了一个名为 MyImage 的 UIImage 子类。 MyImage 显然响应了最初由 UIImage 实现的每个方法。我想完全隐藏 UIImage 实现,例如 MyImage 重新声明了一个方法,如:
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets;
到
- (MyImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets;
我尝试编写如下实现:
- (MyImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets {
UIImage *original = [super resizableImageWithCapInsets:capInsets];
MyImage *result = [[[self class] alloc] initWithUIImage:original];
return result;
}
- (id) initWithUIImage:(UIImage *)image {
// HOW TO IMPLEMENT THIS METHOD???
}
但我停在了 initWithUIImage 方法。如何在不使用合成的情况下实现这种行为?
【问题讨论】:
-
也许你可以考虑让你的班级成为proxy。这样你就可以只公开你想要的方法。
标签: ios objective-c oop subclass