【问题标题】:clickable imageview and buttonview in a cell(UITableView or collectionView)单元格中的可点击图像视图和按钮视图(UITableView 或 collectionView)
【发布时间】:2016-10-30 03:04:12
【问题描述】:

我有一个关于 ios objective-c 的 UI 设计问题。单页需要显示数千张产品图片,每行5个产品,每张图片下每个产品2行信息。如果用户点击产品图片,我需要将其添加到购物车。此外,我需要在每个产品图片下添加一个小按钮。如果用户单击该按钮,我将显示一个窗口,允许用户为该产品写注释。

如何设计这种用户界面?谢谢。

【问题讨论】:

  • 只是将按钮添加为子视图,这就是您的意思?
  • 如何知道点击了哪个按钮和哪个图片?
  • 快速还是客观?
  • 你明白我的回答吗?

标签: ios objective-c uitableview ipad collectionview


【解决方案1】:

在 cellForRowAtIndexPath 中: ip是indexPath

cell.btn.tag = ip.row;
[cell.btn addTarget:self action:@selector(btnclk:) forControlEvents:UIControlEventTouchUpInside];

转到视图控制器并添加此函数,每次调用任何按钮时都会调用该函数...每个按钮都有唯一的标签(因为原始数字),因此您可以通过其编号为每个按钮设置条件。 ..

-(void)btnclk:(UIButto*)sender
{
     if (sender.tag == 0) 
      // btn clicked from cell number 0
}

我是用 iPhone 写的,所以当我使用 PC 时会写更多...

【讨论】:

    【解决方案2】:

    代码如下:

    UIButton*btnLink;//create button
    
    btnLink=[[UIButton alloc]initWithFrame:CGRectMake(8, 8, self.view.frame.size.width, 77)];//set frame
    
    [btnLink setTitle:[@"yourTitle" forState:UIControlStateNormal];
    
    btnLink.tag = indexPath.row;//set tag 
    
    [btnLink addTarget:self action:@selector(linkClick:) forControlEvents:UIControlEventTouchUpInside];//set action
    
    [cell addSubview:btnLink];
    
    
    
    -(IBAction)linkClick:(id)sender{
    
    UIButton *btnSender = sender;
    
    NSLog(@"btnSender.tag====>%ld",(long)btnSender.tag);//check your clicked button tag number
    
    NSDictionary *dS;
    
    dS= [yourArray objectAtIndex:btnSender.tag];
    
    NSString*myurl=[dS objectForKey:@"link"];
    
    NSURL *url = [NSURL URLWithString:@"yourURL OR ANYTHING"];
    [[UIApplication sharedApplication] openURL:url];
    

    【讨论】:

      【解决方案3】:
      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
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-19
        • 1970-01-01
        相关资源
        最近更新 更多