Last active
August 29, 2015 14:10
-
-
Save bobspryn/3af94e7bb7065c47393b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// View Controller | |
// | |
- (void) viewDidLoad { | |
[super viewDidLoad]; | |
RAC(self.viewModel, username) = [myTextfield rac_textSignal]; | |
RACSignal *usernameIsValidSignal = RACObserve(self.viewModel, usernameValid); | |
RAC(self.goButton, alpha) = [usernameIsValidSignal | |
map: ^(NSNumber *valid) { | |
return valid.boolValue ? @1 : @0.5; | |
}]; | |
RAC(self.goButton, enabled) = usernameIsValidSignal; | |
RAC(self.avatarImageView, image) = RACObserve(self.viewModel, userAvatarImage); | |
RAC(self.userNameLabel, text) = RACObserve(self.viewModel, userFullName); | |
@weakify(self); | |
[[[RACSignal merge:@[RACObserve(self.viewModel, tweets), | |
RACObserve(self.viewModel, allTweetsLoaded)]] | |
bufferWithTime:0 onScheduler:[RACScheduler mainThreadScheduler]] | |
subscribeNext:^(id value) { | |
@strongify(self); | |
[self.tableView reloadData]; | |
}]; | |
[[self.goButton rac_signalForControlEvents:UIControlEventTouchUpInside] | |
subscribeNext: ^(id value) { | |
@strongify(self); | |
[self.viewModel getTweetsForCurrentUsername]; | |
}]; | |
} | |
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
// if table section is the tweets section | |
if (indexPath.section == 0) { | |
MYTwitterUserCell *cell = | |
[self.tableView dequeueReusableCellWithIdentifier:@"MYTwitterUserCell" forIndexPath:indexPath]; | |
// grab the cell view model from the vc view model and assign it | |
cell.viewModel = self.viewModel.tweets[indexPath.row]; | |
return cell; | |
} else { | |
// else if the section is our loading cell | |
MYLoadingCell *cell = | |
[self.tableView dequeueReusableCellWithIdentifier:@"MYLoadingCell" forIndexPath:indexPath]; | |
[self.viewModel loadMoreTweets]; | |
return cell; | |
} | |
} | |
// | |
// MYTwitterUserCell | |
// | |
// this could also be in cell init | |
- (void) awakeFromNib { | |
[super awakeFromNib]; | |
RAC(self.avatarImageView, image) = RACObserve(self, viewModel.tweetAuthorAvatarImage); | |
RAC(self.userNameLabel, text) = RACObserve(self, viewModel.tweetAuthorFullName); | |
RAC(self.tweetTextLabel, text) = RACObserve(self, viewModel.tweetContent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[self.tableView loadMoreTweets];
should be[self.viewModel loadMoreTweets];