Created
August 26, 2015 14:18
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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