简体   繁体   中英

How to get Tag of button by clicking from cell?

I add Tag for the each buttons in cell(button is single), when is built TableView as:

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

Where hiddenButtonWithIdCell is button name (Outlet property):

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

Important: outlet in the file cell.h

At file where I loop table I have (so event action here):

Important: (Both the methods in the same file)

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

But at:

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

sender.tag is NSInterger so you should log this like that:

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

Check here for more info about using button's tag with segue:

How to pass prepareForSegue: an object

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM