User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







objective-c:examples:indexpath_for_custom_cell

indexPath.row for IBAction Button in a Custom Cell

to get the indexPath.row for a IBAction Button in your Custom Cell simply do this

/**
* 1. Connect the Button from the Custom Cell to your ViewController.h as IBAction
* 2. add the following code to your ViewController.m
*/
 
- (IBAction)buildButton:(id)sender forEvent:(UIEvent *)event {
 
    UIButton *button = (UIButton *)sender;
    UITableViewCell *cell = (UITableViewCell *)button.superview;
    UITableView *tableView = (UITableView *)cell.superview;
    NSIndexPath *indexPath = [tableView indexPathForCell:cell];
 
    NSLog(@"IBAction Button selected row %d", indexPath.row);
}

output

  2013-03-24 12:45:54.519 cppApp[6017:c07] IBAction Button selected row 2

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
objective-c/examples/indexpath_for_custom_cell.txt · Last modified: 2024/02/16 01:06 (external edit)

Impressum Datenschutz