2010-07-15 81 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

相关问题