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;
}

我不是在 xib 中创建 uimageview,而是在代码中。那么如何检测哪个图像开始并拖动到哪里,最后在哪个图像结束?

更新

我已经添加了这个

- (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);
}

但是,它不记录。

4

0 回答 0