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"];
}
@blakewatters
Copy link
Author

Greg -

This afternoon I was actually working on the Loading/Error/Empty states within the model. Continuing the trend of trying to stay out of the inheritance hierarchy and let you do your own thing, I am adding delegate hooks for the events and there will be support for showing/hiding an overlay (but you can nil the views to disable). In GateGuru we also make heavy use of table and footer items and support for that will be baked in, so you can imagine hooking into the delegates for your Loading/Finished loading and just hiding/showing the loading cells as you feel appropriate.

For the built in display support, I am anticipating drawing an overlay that matches the frame of the table and then drawing the views into it.

We are definitely also going to add first-class support for using XIBs for the table cells as well -- I'll get that in place once I finish the foundational work next week. What I would really like to wind up with a month or so down the road is the ability to generate forms for individual objects in addition to the collection work already in progress. I'd like to be able to do the full Master > Detail application style with object mapping driven table views.

This is total pseudo-code (the code above already works btw), but you could imagine something like...

[RKTableViewFormModel modelForObject:user withBlock:^(RKTableViewFormModel* model) {
    [model addTextFieldForAttribute:@"login" withLabel:@"Login"];
    [model addTextFieldForAttribute:@"password" withLabel:@"Password" secure:YES];
    [model addSubmitButtonWithLabel:@"Login" onSubmitBlock:^(User* user) {
        [user login];
    }];
}];

@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