相关疑难解决方法(0)

检测在UITableView中按下了哪个UIButton

我有一个UITableView5 UITableViewCells.每个单元格包含一个UIButton设置如下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     NSString *identifier = @"identifier";
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
     if (cell == nil) {
         cell = [[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
         [cell autorelelase];

         UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 5, 40, 20)];
         [button addTarget:self action:@selector(buttonPressedAction:) forControlEvents:UIControlEventTouchUpInside];
         [button setTag:1];
         [cell.contentView addSubview:button];

         [button release];
     }

     UIButton *button = (UIButton *)[cell viewWithTag:1];
     [button setTitle:@"Edit" forState:UIControlStateNormal];

     return cell;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:在buttonPressedAction:方法中,我如何知道按下了哪个按钮.我考虑过使用标签,但我不确定这是最好的路线.我希望能够以某种方式标记indexPath到控件上.

- (void)buttonPressedAction:(id)sender
{
    UIButton *button = (UIButton …
Run Code Online (Sandbox Code Playgroud)

iphone uibutton uitableview ios

211
推荐指数
8
解决办法
13万
查看次数

在UITableViewCell中单击获取按钮

我有一个视图控制器,具有表格视图和表格单元格模板的单独笔尖.单元格模板有一些按钮.我想访问按钮单击以及在我已定义表视图的视图控制器内单击的单元格的索引.

所以,我有ViewController.hViewController.m在那里我有UITableViewTableTemplate.h,TableTemplate.mTableTemplate.xib在那里我有定义的笔尖.我想要单元格索引的按钮单击事件ViewController.m.

有什么帮助,我该怎么办?

objective-c uibutton uitableview ios

134
推荐指数
12
解决办法
20万
查看次数

标签 统计

ios ×2

uibutton ×2

uitableview ×2

iphone ×1

objective-c ×1