views:

57

answers:

2

Hi All, 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

+1  A: 

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)

mvds
A: 

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];
chilitechno.com