带有3x3网格按钮子视图的UITableView

时间:2010-12-03 11:41:29

标签: iphone uitableview

我真的很难让它有效地发挥作用。基本上我需要一个3x3滚动按钮网格。我需要知道按下哪个按钮,所以当我创建一个新单元格时,我会执行以下操作

    button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.frame = CGRectMake(20, 20, 80, 80);
    button1.opaque = NO;
    button1.showsTouchWhenHighlighted = NO;
    [button1 addTarget:self action:@selector(buttonClick:)
      forControlEvents:UIControlEventTouchUpInside];
    button1.tag = 0;
    [foodCell.contentView addSubview:button1];


    button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    button2.frame = CGRectMake(120, 20, 80, 80);
    button2.opaque = NO;
    button2.showsTouchWhenHighlighted = NO;
    [button2 addTarget:self action:@selector(buttonClick:)
      forControlEvents:UIControlEventTouchUpInside];    
    button2.tag = 1;
    [foodCell.contentView addSubview:button2];


    button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    button3.frame = CGRectMake(220, 20, 80, 80);
    button3.opaque = NO;
    button3.showsTouchWhenHighlighted = NO;
    [button3 addTarget:self action:@selector(buttonClick:)
      forControlEvents:UIControlEventTouchUpInside];    
    button3.tag = 2;
    [foodCell.contentView addSubview:button3];`

现在当按下按钮时,我使用超级视图获取单元格,然后使用标记进行一些数学计算,以确定我需要查看的数组中的哪个索引。这似乎有效,但我还需要在已按下的按钮上显示一个复选标记,有点像购物清单,一旦按下一个项目,它就会被勾选,也可以不勾选。我正在努力寻找一种有效的方法来实现这一切....有没有人有任何想法,我会非常感激,因为我已经被困了一段时间了。

非常感谢

Jules

1 个答案:

答案 0 :(得分:0)

您是否只能从行动sender的{​​{1}}获取点击按钮的实例,然后在该按钮上添加类似于您的复选标记的视图?