Reputation: 51
I have a UITableView which has custom cells as its rows. In these custom cells they have 2 buttons.
I catch the click of the button in the custom cell class. Just wondering how i pass that event from the custom cell class through to the parent view controller that is holding the UITableView control. Advice?
Thanks
Upvotes: 4
Views: 5536
Reputation: 1575
You can do this:
- (void)buttonTapped:(id)sender event:(id)event
{
CGPoint touchPosition = [[[event allTouches] anyObject] locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchPosition];
if (indexPath != nil)
{
//do Something here
}
}
// in cellForForAtIndexPath, bind the selector:
UIButton *button = (UIButton *)[cell viewWithTag:1];
[button addTarget:self action:@selector(buttonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
Upvotes: 4
Reputation: 47114
You can specify the actions a UIButton performs using
[button addTarget:self action:@selector(doStuff:)
forControlEvents:UIControlEventTouchDown];
review the UIControl
documentation for more information. (UIButton inherits from UIControl)
Upvotes: 2