Last active
August 29, 2015 14:25
-
-
Save bricklife/439e69c97f251b4364db to your computer and use it in GitHub Desktop.
RACDelegateProxy in UITableVIewController
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
#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