开发者

Selecting Imageview from a table view cells

I have a table view and have 5 rows in it.In each row i have 4 imageView on which images are shown .Now i want to select an image from the first row.How can i do it.Please help 开发者_如何学GoThanks, Christy


I would create UIButtons with the images as subviews. And with the button you call your actions.

Something like this:

// Initialize your subviews for the cell and Tag them //...

NSUInteger row = [indexPath row];

if(row==0)
    {
    UIImage* image1 = [UIImage imageNamed:@"image1.png"];
    [yourbutton1 addSubview:image];}

// ...

else{...}

return cell;

. . .


When you say "select an image from the first row", do you mean something like "let the user tap on an image in the first row and highlight it" ?

If so, then you will want to investigate the following:

You will need to link the ImageView (IV) with your model somehow. So your model is an array of 5 (for your rows) each containing an array of 4 images (to show in each row).

You could set the tag of each IV to indicate the offset in the array. So now you know which IV is being tapped by the combination of the row it is in, and the tag it has.

If you want an action to be performed when the user taps your image, have you considered using a UIButton object and putting the image in that instead?

You may also want to make your IV allow user interaction, because they do not by default.

yourImageView.setUserInteractionEnabled = YES;

Hope this helps, good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜