类 超类 子类

发布于 2024-09-15 16:36:39 字数 1802 浏览 6 评论 0原文

我正在尝试将两个子类设为一个类:

// 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

埋葬我深情 2024-09-22 16:36:39

@synthesize 位于 ImageScrollView@implementation 中,而不是位于子类中。

self.ISVportrate 没有意义(除非你有一个名为 -ISVportrate 的方法,它也没有意义)。

听起来您还没有完全理解面向对象编程。您可能想要创建一个子类的适当实例,并将其指定为包含它的任何视图的子视图......

The @synthesize goes in the @implementation of ImageScrollView, 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....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文