Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has anybody made self updating mutable table view based on a RACSignal?

Now that there's a full support for KVO, has anybody made a mutable table view that takes a RACSignal as its dataSource? Ideally something that doesn't require any configuration.

RACSignal *commentsSignal;
UITableView *table = [UITableView new];
table.dataSourceSignal = commentsSignal;
[self.view addSubview:table];
// No more basic config
like image 540
Michael Avatar asked Apr 25 '13 18:04

Michael


2 Answers

ReactiveCocoa 3.0 (currently in development) adds a category on UITableView that does just that.

I haven't updated it in a couple weeks, but I made an early podspec for it: https://gist.github.com/adlai-holler/ae321c3398d7db9a55c0

like image 117
Adlai Holler Avatar answered Oct 24 '22 23:10

Adlai Holler


Yes, I have created a 'binding helper' that binds a table view to a signal:

http://www.scottlogic.com/blog/2014/05/11/reactivecocoa-tableview-binding.html

You can use it to bind a signal to table view where the cell is defined in a nib, as shown below:

// create a cell template
UINib *nib = [UINib nibWithNibName:@"CETweetTableViewCell" bundle:nil];

// bind the ViewModels 'searchResults' property to a table view
[CETableViewBindingHelper bindingHelperForTableView:self.searchResultsTable
                        sourceSignal:RACObserve(self.viewModel, searchResults)
                        templateCell:nib];

In the above example the table view is bond to an NSArray property on a view model via RACObserve(self.viewModel, searchResults), however any RACSignal that emits an array will bind just fine.

like image 2
ColinE Avatar answered Oct 24 '22 23:10

ColinE