类超类子类

时间:2010-08-23 00:04:25

标签: objective-c class subclass superclass

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

// 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个错误......这是我第一次上课...帮助我理解,我想我几乎做对了。

1 个答案:

答案 0 :(得分:3)

@synthesize位于@implementation的{​​{1}},不在子类中。

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

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