Skip to content

Instantly share code, notes, and snippets.

@michaelochs
Created August 26, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelochs/ace1899c2689204f462f to your computer and use it in GitHub Desktop.
Save michaelochs/ace1899c2689204f462f to your computer and use it in GitHub Desktop.
An example of how we at HRS expand the `UITableViewDelegate` protocol to trigger custom actions from a cell and communicate them to the table view's delegate.
@protocol HRSStepperTableViewCellDelegate<UITableViewDelegate>
- (void)tableView:(UITableView *)tableView didChangeStepperValue:(UIStepper *)stepper forRowWithIndexPath:(NSIndexPath *)indexPath;
@end
@implementation HRSStepperTableViewCell
- (UITableView *)tableView {
UIView *superview = self.superview;
while (superview != nil && [superview isKindOfClass:[UITableView class]] == NO) {
superview = superview.superview;
}
return (UITableView *)superview;
}
- (IBAction)stepperValueChanged:(id)sender {
if (sender != self.stepper) {
return;
}
UITableView *tableView = self.tableView;
id<HRSStepperTableViewCellDelegate> delegate = (id<HRSStepperTableViewCellDelegate>)tableView.delegate;
if ([delegate respondsToSelector:@selector(tableView:didChangeStepperValue:forRowWithIndexPath:)]) {
[delegate tableView:tableView didChangeStepperValue:sender forRowWithIndexPath:[tableView indexPathForCell:self]];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment