views:

93

answers:

2

Hi
i have images in my UIScrollview which is added in View.
plz go through my code-

@interface ScrollViewController : UIScrollView <UIScrollViewDelegate>{

    UIImageView *productImage;
    UILabel *productName;
    NSArray *productArray;
}
@property(nonatomic,retain) UIImageView *productImage;
@property(nonatomic,retain) UILabel *productName;
@property(nonatomic,retain) NSArray *productArray;

- (id)initWitProducts:(NSArray*)_data;
*.m*

- (id)initWitProducts:(NSArray *)_data
    if ((self = [super init])){
         productArray=[[NSArray alloc]initWithArray:_data];       
         [self setFrame:CGRectMake(0, 0, 320, 480)];
         int countList=[self.productArray count];
         self.contentSize=CGSizeMake(320, 585);


        for(int i=0;i<countList;i++)
        {

            productImage=[[UIImageView alloc]initWithImage:[UIImage imageNamed:[[productArray objectAtIndex:i]objectForKey:@"ProductImage"]]];

            productImage.frame=CGRectMake(95, 35+i*125, 100, 100);
            [productImage setUserInteractionEnabled:YES];
            [self addSubview:productImage];
        }
       return self;     
    }


 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event
 {
     if([[touches anyObject]view]==self.productImage)
     NSlog(@"Image Touched");
}

This is working well but only for last image in Array
the touchesBegan is not working for other images in Array
what should i add here to detect the touch on all the images(1st,2nd,...etc) of Array
Plz Plz help me i m new in Iphone & i have to do this

lots of thanks in advance for any help

A: 

You know all the positions of images on UIScrollview, so you can touch position on scrollView into images position in you array. And another point - you should never compare objective-c objects using "==", always use "isEqual" method instead.

eviltrue
sorry..but i did't got your clue.
can u update my code....plz??
A: 

Hi Vladimir,

I am having the same issue, can you please post teh answer if you found a solution for this issue.

Thanks.