Skip to content

Instantly share code, notes, and snippets.

@blakewatters
Created August 5, 2011 15:53
Show Gist options
  • Save blakewatters/1127828 to your computer and use it in GitHub Desktop.
Save blakewatters/1127828 to your computer and use it in GitHub Desktop.
- (void)viewDidLoad {
[super viewDidLoad];
// Configure RestKit Logging
RKLogConfigureByName("RestKit/UI", RKLogLevelTrace);
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
RKLogConfigureByName("RestKit/Network*", RKLogLevelDebug);
// Configure the object manager
RKObjectManager* manager = [RKObjectManager objectManagerWithBaseURL:@"http://localhost:4567/"];
[manager.mappingProvider setMapping:[RKObjectMapping mappingForClass:[Contact class] withBlock:^(RKObjectMapping* mapping) {
[mapping mapKeyPath:@"first_name" toAttribute:@"firstName"];
[mapping mapKeyPath:@"last_name" toAttribute:@"lastName"];
[mapping mapKeyPath:@"email_address" toAttribute:@"emailAddress"];
}] forKeyPath:@"contacts"];
__tableViewModel = [RKTableViewModel tableViewModelForTableViewController:self];
[__tableViewModel mapObjectsWithClass:[Contact class] toTableViewCellClass:[UITableViewCell class] withBlock:^(RKTableViewCellMapping* cellMapping) {
cellMapping.cellStyle = UITableViewCellStyleSubtitle;
cellMapping.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[cellMapping mapKeyPath:@"fullName" toAttribute:@"textLabel.text"];
[cellMapping mapKeyPath:@"emailAddress" toAttribute:@"detailTextLabel.text"];
cellMapping.onSelectCellForObject = ^ (UITableViewCell* cell, Contact* contact) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Cell Selected!"
message:[NSString stringWithFormat:@"You selected '%@'", contact.fullName]
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
};
// TODO: configureCell:forObject:atIndexPath:
}];
[__tableViewModel loadTableFromResourcePath:@"/contacts.json"];
}
@grgcombs
Copy link

grgcombs commented Aug 5, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment