Классы Суперклассы Подклассы - PullRequest
0 голосов
/ 23 августа 2010

Я пытаюсь сделать два подкласса классом:

// 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 Ответ

3 голосов
/ 23 августа 2010

@synthesize входит в @implementation из ImageScrollView, а не в подкласс.

self.ISVportrate не имеет смысла (если у вас не было метода с именем -ISVportrate, который быЭто тоже не имеет смысла).

Звучит так, будто вы еще не совсем завладели объектно-ориентированным программированием.Вы хотели бы создать соответствующий экземпляр одного из ваших подклассов и назначить его как подпредставление любого представления, содержащего его ....

...