如何通过单击单元格获取按钮标签?

How to get Tag of button by clicking from cell?

我为单元格中的每个按钮添加 Tag(按钮是单个按钮),当构建 TableView 时为:

[cell.hiddenButtonWithIdCell setTag:(int) self.responseObject[@"results"][indexPath.row][@"id"]]; // Value is 4

其中 hiddenButtonWithIdCell 是按钮名称(出口 属性):

@property (weak, nonatomic) IBOutlet UIButton *hiddenButtonWithIdCell;

重要:文件中的出口cell.h

在我循环的文件中 table 我有(所以这里的事件操作):

重要:(两种方法在同一个文件中)

- (IBAction)openDetailsOfDish:(id)sender {
    NSLog(@"Click: %@", [sender tag]); // Here I get correct Tag and equal 20
    [self performSegueWithIdentifier:@"Full" sender:sender];
}

但是在:

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(UIButton*) sender {
    NSLog(@"%@", sender.tag); // Here is wrong tag
}

sender.tag 是 NSInterger 所以你应该这样记录:

NSLog(@"MY SENDER TAG %lu", sender.tag);

在此处查看有关将按钮标签与 segue 结合使用的更多信息:

How to pass prepareForSegue: an object