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
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];
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)
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.