Miken Miken - 11 days ago 6
iOS Question

clickable imageview and buttonview in a cell(UITableView or collectionView)

I have a UI design problem about ios objective-c. there are thousands of product images need to be displayed in a single page,5 products every line,and 2 lines information for each product under each image. If user clicks the product image, I need to add it to shopping cart. moreover,I need to add a small button under each product image.If user click the button, I will display a window to allow user to write notes for that product.

How to design this kind of UI? thank you.

Answer
cell.yourImageView.tag = ip.row;
cell.youreImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
// this maybe repeat to addGesture
// you can user custom UITableViewCell to avoid it
[cell.youreImageView addGestureRecognizer:tap];


- (void)tapClick:(id)sender
{
    UITapGestureRecognizer *tap = sender;
    UIView *view = tap.view;
    if (view.tag == 0) {
        // row 1
    }
}
Comments