Skip to content

Instantly share code, notes, and snippets.

@bricklife
Last active August 29, 2015 14:25
Show Gist options
  • Save bricklife/439e69c97f251b4364db to your computer and use it in GitHub Desktop.
Save bricklife/439e69c97f251b4364db to your computer and use it in GitHub Desktop.
RACDelegateProxy in UITableVIewController
#import "TableViewController.h"
#import <ReactiveCocoa/ReactiveCocoa.h>
#import <ReactiveCocoa/RACDelegateProxy.h>
@interface TableViewController ()
@property (nonatomic, strong) RACDelegateProxy *tableViewDelegate;
@end
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
[[self rac_signalForSelector:@selector(tableView:numberOfRowsInSection:) fromProtocol:@protocol(UITableViewDataSource)] subscribeNext:^(RACTuple *arguments) {
NSLog(@"tableView:numberOfRowsInSection:%@", arguments);
}];
#if 0
self.tableViewDelegate = [[RACDelegateProxy alloc] initWithProtocol:@protocol(UITableViewDelegate)];
[[self.tableViewDelegate signalForSelector:@selector(tableView:didSelectRowAtIndexPath:)] subscribeNext:^(RACTuple *arguments) {
NSLog(@"tableView:didSelectRowAtIndexPath:%@", arguments);
}];
self.tableView.delegate = (id<UITableViewDelegate>)self.tableViewDelegate;
#else
[[self rac_signalForSelector:@selector(tableView:didSelectRowAtIndexPath:) fromProtocol:@protocol(UITableViewDelegate)] subscribeNext:^(RACTuple *arguments) {
NSLog(@"tableView:didSelectRowAtIndexPath:%@", arguments);
}];
// Need to "reset" the cached values of respondsToSelector: of UIKit
self.tableView.delegate = nil;
self.tableView.delegate = self;
#endif
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"original tableView:numberOfRowsInSection:");
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
return cell;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment