Skip to content

Instantly share code, notes, and snippets.

@rogerluan
Created November 18, 2015 16:23
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 rogerluan/fd4fe4a082adbc721102 to your computer and use it in GitHub Desktop.
Save rogerluan/fd4fe4a082adbc721102 to your computer and use it in GitHub Desktop.
Code snippet for blog series.
//TableDelegate.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface TableDelegate : UIControl <UITableViewDelegate>
@property (nonatomic, strong) NSArray *data;
@property (readonly) id selectedData;
@end
//TableDelegate.m
#import "TableDelegate.h"
#import "CustomTableViewCell.h"
@implementation TableDelegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
id data = self.data[indexPath.row];
[((CustomTableViewCell *)cell) configureCellWithData:data];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
_selectedData = self.data[indexPath.row];
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment