2010-07-15 49 views
0

我要讓headerfile Rimage.h和M,我可以在任何地方使用,但我在這裏有一個問題 這是我使頭文件比任何地方都可以使用iPhone

Rimage.h

@class Rahul_imageplaceCordinatesViewController; 

@interface Rimage : NSObject { 

    Rahul_imageplaceCordinatesViewController *vc; 
} 

-(void)addImageSubViewAtX:(CGFloat)x atY:(CGFloat)y; 
@property (nonatomic,copy) Rahul_imageplaceCordinatesViewController *vc; 
+(void)check1; 

@end 

,這是我的.m

@implementation Rimage 
@synthesize vc; 

/// this method let you have image with given X n Y 
- (void)addImageSubViewAtX:(CGFloat)x atY:(CGFloat)y { 
CGRect myImageRect1 = CGRectMake(x, y, 30.0f, 30.0f); 
    UIImageView *myImage1 = [[UIImageView alloc] initWithFrame:myImageRect1]; 

    [myImage1 setImage:[UIImage imageNamed:@"status_finish.gif"]]; 
    myImage1.tag = 1000; 

    myImage1.userInteractionEnabled = YES; 
    [self.view addSubview:myImage1];  
} 
現在我mainVC

我是愈傷組織

NG這樣

- (void)viewDidLoad {  
    Rimage *hw = [[Rimage alloc] init]; 

    //[hw check1]; 
    [Rimage check1]; 
    [hw addImageSubViewAtX:160.0 atY:190.0];   
} 

,但我不能顯示圖像我不知道爲什麼:(

回答

0

首先我注意到的是你的@property你正在在一個VC的視圖控制器的「複製」,我懷疑這是一個壞主意,你只是想分配或保留它。

其次,在addImageSubViewAtX,您有:

[self.view addSubview:myImage1]; 

但是,什麼是自我呢?這是Rimage的實例。我猜你可能是想把圖像添加到vc中的視圖中?我沒有看到vc在你提供的代碼中曾經使用過,所以它是幹什麼用的?

[vc.view addSubview:myImage1]; 
+0

所以我應該怎麼做才能使用這個頭文件只顯示圖像,以便它可以通用? – ram 2010-07-17 02:52:58

+0

如果我這樣做[vc.view addSubview:myImage1]; 那麼它的運行無限 – ram 2010-07-17 04:10:00

相關問題