2010-08-23 95 views
-4

我試圖讓兩個子類:類的子類超類

// 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個錯誤......這是我第一次上課......幫助我理解,我想我已經差不多了。

+0

這是什麼編程語言?將來,請至少在標籤中提及編程語言,但最好也在問題本身中提及。 – Timwi 2010-08-23 00:14:32

+0

對我來說看起來像Objective-C。 – 2010-08-23 00:21:30

+0

iphone sdk xcode objc大聲笑抱歉maaaaate! :P – user422241 2010-08-23 00:29:51

回答

3

@synthesize進入ImageScrollView@implementation,而不是在子類中。

self.ISVportrate沒有意義(除非你有一個方法叫做-ISVportrate,這也沒有任何意義)。

這聽起來像你還沒有完全熟悉面向對象的編程。你會想創建一個你的子類的適當的實例,並將其作爲任何視圖的子視圖包含它......

+2

好吧,我開始喝伏特加,所以我現在不太確定你說什麼,如果你可以詳細闡述一下,我會看清楚它,我相信我會得到它。我現在正在逐步學習。 – user422241 2010-08-23 02:39:55

+0

所以你說@synthesize進入了ImageScrollView的@implementation ...這是否意味着我應該保持ImageScrollView的實現並在ImageScrollView中爲ISVportrate和ISVlandscape重複什麼?因爲現在我沒有執行力度只有接口只圖像滾動視圖: @implementation ISVportrate:ImageScrollView & @implementation ISVlandscape:ImageScrollView 不是:@implementation ImageScrollView。 我不確定關於NSInteger索引...在哪裏必須申報等... 謝謝隊友! – user422241 2010-08-23 02:40:19

+2

請閱讀並重新閱讀:http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html您需要了解面向對象編程的基礎知識才能取得成功。 (真的 - 這是最好的前進方向。) – bbum 2010-08-23 05:39:11