类 超类 子类
我正在尝试将两个子类设为一个类:
// Old code
- (void)setPaging {
[pagingScrollView addSubview:self.ImageScrollView];
}
@interface ImageScrollView : UIScrollView <UIScrollViewDelegate> {
UIView *imageView;
NSUInteger index;
}
@property (assign) NSUInteger index;
- (void)displayTiledImageNamed:(CGPDFPageRef)page size:(CGSize)imageSize;
@end
@implementation ImageScrollView
@synthesize index;
// ... my methods ...
@end
更改为:
// NEW Code__________________________________________________________*
- (void)setPaging {
if (D == 1) {
// error: request for member 'ISVportrate' in something not a
// structure or union
[pagingScrollView addSubview:self.ISVportrate];
} else if (D == 2) {
//error: request for member 'ISVLandscape' in something not a
// structure or union
[pagingScrollView addSubview:self.ISVLandscape];
}
}
@class ISVportrate;
@class ISVLandscape;
@interface ImageScrollView : UIScrollView <UIScrollViewDelegate> {
UIView *imageView;
NSUInteger index;
}
@property (assign) NSUInteger index;
- (void)displayTiledImageNamed:(CGPDFPageRef)page size:(CGSize)imageSize;
@end
@interface ISVportrate : ImageScrollView {}
@end
@interface ISVLandscape : ImageScrollView {}
@end
@implementation ISVportrate : ImageScrollView
// error: property 'index' attempting to use ivar 'index' declared in
// super class of 'ISVportrate'
@synthesize index;
// ... my methods ...
@end
@implementation ISVLandscape : ImageScrollView
// error: property 'index' attempting to use ivar 'index' declared in
// super class of 'ISVLandscape'
@synthesize index;
// ... my methods ...
@end
我做得不对,对吗?看到上面我有 4 个错误…这是我第一次上课…帮助我理解,我想我几乎已经做对了。
I'm trying to make two subclasses a class:
// Old code
- (void)setPaging {
[pagingScrollView addSubview:self.ImageScrollView];
}
@interface ImageScrollView : UIScrollView <UIScrollViewDelegate> {
UIView *imageView;
NSUInteger index;
}
@property (assign) NSUInteger index;
- (void)displayTiledImageNamed:(CGPDFPageRef)page size:(CGSize)imageSize;
@end
@implementation ImageScrollView
@synthesize index;
// ... my methods ...
@end
Changed to:
// NEW Code__________________________________________________________*
- (void)setPaging {
if (D == 1) {
// error: request for member 'ISVportrate' in something not a
// structure or union
[pagingScrollView addSubview:self.ISVportrate];
} else if (D == 2) {
//error: request for member 'ISVLandscape' in something not a
// structure or union
[pagingScrollView addSubview:self.ISVLandscape];
}
}
@class ISVportrate;
@class ISVLandscape;
@interface ImageScrollView : UIScrollView <UIScrollViewDelegate> {
UIView *imageView;
NSUInteger index;
}
@property (assign) NSUInteger index;
- (void)displayTiledImageNamed:(CGPDFPageRef)page size:(CGSize)imageSize;
@end
@interface ISVportrate : ImageScrollView {}
@end
@interface ISVLandscape : ImageScrollView {}
@end
@implementation ISVportrate : ImageScrollView
// error: property 'index' attempting to use ivar 'index' declared in
// super class of 'ISVportrate'
@synthesize index;
// ... my methods ...
@end
@implementation ISVLandscape : ImageScrollView
// error: property 'index' attempting to use ivar 'index' declared in
// super class of 'ISVLandscape'
@synthesize index;
// ... my methods ...
@end
I am not doing this right, am I? see above I have 4 errors… this is the first time I've made a class… help me understand, I think I've almost got it right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@synthesize
位于ImageScrollView
的@implementation
中,而不是位于子类中。self.ISVportrate 没有意义(除非你有一个名为 -ISVportrate 的方法,它也没有意义)。
听起来您还没有完全理解面向对象编程。您可能想要创建一个子类的适当实例,并将其指定为包含它的任何视图的子视图......
The
@synthesize
goes in the@implementation
ofImageScrollView
, not in the subclass.self.ISVportrate
doesn't make sense (unless you had a method called-ISVportrate
, which wouldn't make sense, either).It sounds like you haven't quite grokked object oriented programming yet. You would want to create an appropriate instance of one of your subclasses and assign that as the subview of whatever view contains it....