Skip to content

Instantly share code, notes, and snippets.

@jeremytregunna
Last active December 24, 2015 08:19
Show Gist options
  • Save jeremytregunna/6770160 to your computer and use it in GitHub Desktop.
Save jeremytregunna/6770160 to your computer and use it in GitHub Desktop.
@implementation SomeVC
- (void)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)path
{
... cell = ....;
[self configureCell:cell forIndexPath:path];
return cell;
}
- (void)configureCell:(MyRatingCell*)cell forIndexPath:(NSIndexPath*)path
{
cell.numberOfStars = [self.ratingsController starCountAtIndexPath:path];
cell.body = [self.ratingsController reviewBodyAtIndexPath:path];
cell.name = [self.ratingsController usernameAtIndexPath:path];
cell.date = [self.ratingsController reviewedDateAtIndexPath:path];
}
@end
@interface RatingsController : NSObject
// all the selectors we use here + an initializer that takes a piece of model data, i.e., an array
@end
@implementation RatingsController
- (instancetype)initWithArray:(NSArray*)array
{
if((self = [super init]))
_array = [array copy];
return self;
}
- (NSUInteger)starCountAtIndexPath:(NSIndexPath*)path
{
return [[self.array[path.row] stars] unsignedIntegerValue];
}
// ...
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment