0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *hlCellID = @"hlCellID";

UITableViewCell *hlcell = [tableView dequeueReusableCellWithIdentifier:hlCellID];
if(hlcell == nil) {
    hlcell =  [[[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault reuseIdentifier:hlCellID] autorelease];
    hlcell.accessoryType = UITableViewCellAccessoryNone;
    hlcell.selectionStyle = UITableViewCellSelectionStyleNone;
}

int section = indexPath.section;
NSMutableArray *sectionItems = [sections objectAtIndex:section];

int n = [sectionItems count];
int i=0, i1=0;

while(i<n){
    int yy = 5 + i1*65;
    int j=0;
    for(j=0; j<4;j++){
        if (i>=n) break;
        Item *item = [sectionItems objectAtIndex:i];

        CGRect rect = CGRectMake(5 + j* 65, yy, 55, 55);
        UIImageView *imageview=[[UIImageView alloc] initWithFrame:rect];
        [imageview setFrame:rect];
        UIImage *image = [UIImage imageNamed:item.imagepath];
        [imageview setImage:image];
        [imageview setUserInteractionEnabled:YES];
        [hlcell.contentView addSubview:imageview];
        [imageview release];
        i++;
    }
    i1 = i1+1;
}

return hlcell;
}

I am not create the uimageview in xib but in code. So how to detect which image is begin and drag to where and finally end at which image?

UPDATE

I had add this

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];

//CGPoint location = [touch locationInView:self.view];
if (touch.view == imageview)
NSLog(@"%@", touch.view);
}

However, it does not log.

Alan Lai
  • 1,094
  • 7
  • 18
  • 41
  • do you want to detect that the user tapped on the image ? – Arun Sep 03 '12 at 06:33
  • nop, i use gesture cannot, I want to know user began with which image then end with which image. gesture only can recognize user touchup an image only – Alan Lai Sep 03 '12 at 06:41
  • so you want to use gesture is it right?... – Arun Sep 03 '12 at 06:47
  • nop, i want use touchbegan, touchmoved and touchended – Alan Lai Sep 03 '12 at 06:47
  • 1
    have u seen the @Randeep's two links ... – Arun Sep 03 '12 at 06:50
  • touches end code........... - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; lastTouch = [touch locationInView:imageView]; } – Arun Sep 03 '12 at 06:54
  • You have to set userinteractionEnabled = YES for all your UIImageViews otherwise they will not receive touch events. i hope now it will work... – Arun Sep 03 '12 at 07:11
  • is it works means update me ASAP... – Arun Sep 03 '12 at 07:17
  • work partial. It can detect touch but cannot recognize which imageview is clicked because uiimageview is declared local. – Alan Lai Sep 03 '12 at 07:27
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/16177/discussion-between-spynet-and-alan-lai) – Arun Sep 03 '12 at 08:08

0 Answers0