tags:

views:

22

answers:

1

i want to make headerfile Rimage.h and m that i can use anywhere but i have a problem here this is my

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

and this is my .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];    
}

now in my mainVC

i am calling like this

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

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

but i cant display that image i dont know why :(

A: 

First I noticed is your @property you are making a "copy" of the ViewController in vc, I suspect that's a bad idea, you just want to assign or retain it.

Second, in addImageSubViewAtX, you have:

[self.view addSubview:myImage1];

But what is self there? It is the instance of Rimage. I'm guessing that perhaps you meant to add the image to the view in vc?? I don't see that vc is ever used in the code you provided so what is it for?

[vc.view addSubview:myImage1];
progrmr
so what should i do in order to display image using this headerfile only so that it can be generic??
ram
if i do this [vc.view addSubview:myImage1];then its running infinite
ram