-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.

Nathan Osman
  • 71,149
  • 71
  • 256
  • 361
user422241
  • 11
  • 5

1 Answers1

3

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....

bbum
  • 162,346
  • 23
  • 271
  • 359
  • 2
    ok I've kind of started drinking vodka so Im not too sure right now what your saying if you could elaborate a little I will look at it sober and I'm sure i'll get it. I'm literally learning in leaps and bounds right now. – user422241 Aug 23 '10 at 02:39
  • so you say that the @synthesize goes in the @implementation of ImageScrollView... does that mean that I should keep the implementation of ImageScrollView and duplicate whats inside ImageScrollView for ISVportrate & ISVlandscape? because right now I have no Implimentation only Interface for Image scrollView only: @implementation ISVportrate : ImageScrollView & @implementation ISVlandscape : ImageScrollView not: @implementation ImageScrollView. I am unsure about the NSInteger index... where must it be declaired etc... Thanks mate! – user422241 Aug 23 '10 at 02:40
  • 2
    Go read and re-read this: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html You need to understand the basics of Object Oriented programming to be successful. (Really -- it is the best way forward.) – bbum Aug 23 '10 at 05:39