Skip to content

Instantly share code, notes, and snippets.

@bestimmaa
Forked from bunnyhero/ReusableCellExample.m
Created August 16, 2016 19:40
Show Gist options
  • Save bestimmaa/ee374e7188f24b2520fcba19e8a1a440 to your computer and use it in GitHub Desktop.
Save bestimmaa/ee374e7188f24b2520fcba19e8a1a440 to your computer and use it in GitHub Desktop.
Example of Reactive Cocoa binding for a reusable cell.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:REUSABLE_CELL_ID];
UILabel *label = (UILabel *)[cell viewWithTag:VIEW_TAG];
Model *someModel = [self getModelFromIndexPath:indexPath];
// `takeUntil:` makes the RACObserve() signal complete (and thus breaks the subscription)
// when the cell is recycled.
RAC(label, text) = [RACObserve(someModel, someKey)
takeUntil:cell.rac_prepareForReuseSignal];
return cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment