Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>AppDelegate:</p> <p>@</p> <pre><code>interface AppDelegate () @property (nonatomic, strong, readwrite) RKObjectManager *objectManager; @property (nonatomic, strong, readwrite) RKManagedObjectStore *objectStore; @end; @implementation AppDelegate @synthesize window = _window, isAuthenticated; @synthesize objectManager; @synthesize objectStore; - (void)initializeRestKit { //self.objectManager = [RKObjectManager managerWithBaseURLString:@"http://falling-ocean-1302.herokuapp.com"]; self.objectManager = [RKObjectManager managerWithBaseURLString:@"http://falling-ocean-1302.herokuapp.com"]; self.objectManager.serializationMIMEType = RKMIMETypeJSON; self.objectManager.acceptMIMEType = RKMIMETypeJSON; self.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"MMmtvzme.sqlite"]; self.objectManager.objectStore = self.objectStore; self.objectManager.mappingProvider = [MMMappingProvider mappingProviderWithObjectStore:self.objectStore]; self.objectManager.client.cachePolicy = RKRequestCachePolicyNone; RKLogConfigureByName("RestKit", RKLogLevelTrace); RKLogConfigureByName("RestKit/Network", RKLogLevelTrace); RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace); RKLogConfigureByName("RestKit/Network/Queue", RKLogLevelTrace); // Enable automatic network activity indicator management objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES; [objectManager.router routeClass:[MMRequest class] toResourcePath:@"/requests" forMethod:RKRequestMethodPOST]; [objectManager.router routeClass:[MMRequest class] toResourcePath:@"/requests" forMethod:RKRequestMethodDELETE]; [objectManager.router routeClass:[MMAnswer class] toResourcePath:@"/requests/:request_id/answers" forMethod:RKRequestMethodPOST]; } </code></pre> <p>Ok this is the code from the first UITableViewController</p> <pre><code> @interface MMMyRequestList () @property (nonatomic, strong) RKFetchedResultsTableController *tableController; @end @implementation MMMyRequestList @synthesize tableController; - (void)viewDidLoad { [super viewDidLoad]; [self configureRKTableController]; [self configureCellMapping]; [self useCustomNib]; } - (void)configureRKTableController{ self.tableController = [[RKObjectManager sharedManager] fetchedResultsTableControllerForTableViewController:self]; self.tableController.autoRefreshFromNetwork = YES; self.tableController.pullToRefreshEnabled = YES; self.tableController.resourcePath = @"/requests"; self.tableController.variableHeightRows = YES; NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"request_id" ascending:NO]; self.tableController.sortDescriptors = [NSArray arrayWithObject:descriptor]; tableController.canEditRows = YES; } - (void)configureCellMapping{ RKTableViewCellMapping *cellMapping = [RKTableViewCellMapping cellMapping]; cellMapping.cellClassName = @"MMRequestCell"; cellMapping.reuseIdentifier = @"MMRequest"; cellMapping.rowHeight = 100.0; [cellMapping mapKeyPath:@"title" toAttribute:@"requestLabel.text"]; [cellMapping mapKeyPath:@"user.first_name" toAttribute:@"userLabel.text"]; cellMapping.onSelectCellForObjectAtIndexPath = ^(UITableViewCell *cell, id object, NSIndexPath* indexPath) { MMMyRequestListAnswer * uic = [self.storyboard instantiateViewControllerWithIdentifier:@"MMMyRequestListAnswer"]; MMRequest *request = [self.tableController objectForRowAtIndexPath:indexPath]; if ([uic respondsToSelector:@selector(setRequest:)]) { [uic setRequest:request]; } [self.navigationController pushViewController:uic animated:YES]; }; [tableController mapObjectsWithClass:[MMRequest class] toTableCellsWithMapping:cellMapping]; } - (void)useCustomNib{ [self.tableView registerNib:[UINib nibWithNibName:@"MMRequestCell" bundle:nil] forCellReuseIdentifier:@"MMRequest"]; } - (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error { UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; NSLog(@"Hit error: %@", error); } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; /** Load the table view! */ [tableController loadTable]; } </code></pre> <p>After clicking on a cell the Detail UIViewController come into action</p> <pre><code> interface MMMyRequestListAnswer () @property (nonatomic, strong) RKFetchedResultsTableController *tableController; @end @implementation MMMyRequestListAnswer @synthesize tableHeaderView, requestTextLabel; @synthesize request; @synthesize tableController; - (void)viewDidLoad { [super viewDidLoad]; [self configureRKTableController]; [self configureCellMapping]; [self useCustomNib]; } - (void)configureRKTableController{ self.tableController = [[RKObjectManager sharedManager] fetchedResultsTableControllerForTableViewController:self]; self.tableController.autoRefreshFromNetwork = YES; self.tableController.pullToRefreshEnabled = YES; self.tableController.resourcePath = [NSString stringWithFormat:@"/requests/%i/answers", [self.request.request_id intValue]]; self.tableController.variableHeightRows = YES; NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"answer_id" ascending:NO]; self.tableController.sortDescriptors = [NSArray arrayWithObject:descriptor]; } - (void)configureCellMapping{ RKTableViewCellMapping *cellMapping = [RKTableViewCellMapping cellMapping]; cellMapping.cellClassName = @"MMRequestAnswerCell"; cellMapping.reuseIdentifier = @"MMAnswer"; cellMapping.rowHeight = 80.0; [cellMapping mapKeyPath:@"text" toAttribute:@"answerLabel.text"]; [cellMapping mapKeyPath:@"user.first_name" toAttribute:@"userLabel.text"]; [tableController mapObjectsWithClass:[MMAnswer class] toTableCellsWithMapping:cellMapping]; } - (void)useCustomNib{ [self.tableView registerNib:[UINib nibWithNibName:@"MMRequestAnswerCell" bundle:nil] forCellReuseIdentifier:@"MMAnswer"]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; /** Load the table view! */ [tableController loadTable]; } </code></pre> <p>The Object Mapping is handled in this Class:</p> <pre><code>@implementation MMMappingProvider @synthesize objectStore; + (id)mappingProviderWithObjectStore:(RKManagedObjectStore *)objectStore { return [[self alloc] initWithObjectStore:objectStore]; } - (id)initWithObjectStore:(RKManagedObjectStore *)theObjectStore { self = [super init]; if (self) { self.objectStore = theObjectStore; [self setObjectMapping:[self requestObjectMapping] forResourcePathPattern:@"/requests" withFetchRequestBlock:^NSFetchRequest *(NSString *resourcePath) { NSFetchRequest *fetchRequest = [MMRequest fetchRequest]; return fetchRequest; }]; [self setObjectMapping:[self answerObjectMapping] forResourcePathPattern:@"/requests/:request_id/answers" withFetchRequestBlock:^NSFetchRequest *(NSString *resourcePath) { NSFetchRequest *fetchRequest = [MMAnswer fetchRequest]; fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"answer_id" ascending:YES]]; return fetchRequest; }]; [self setSerializationMapping:[self.requestObjectMapping inverseMapping] forClass:[MMRequest class]]; [self setSerializationMapping:[self.answerObjectMapping inverseMapping] forClass:[MMAnswer class]]; [self setSerializationMapping:[self.userObjectMapping inverseMapping] forClass:[MMUser class]]; } return self; } - (RKManagedObjectMapping *)userObjectMapping { RKManagedObjectMapping *mapping = [RKManagedObjectMapping mappingForEntityWithName:@"MMUser" inManagedObjectStore:self.objectStore]; mapping.primaryKeyAttribute = @"user_id"; [mapping mapAttributes:@"first_name", nil]; [mapping mapKeyPathsToAttributes: @"id", @"user_id", nil]; return mapping; } - (RKManagedObjectMapping *)answerObjectMapping { RKManagedObjectMapping *mapping = [RKManagedObjectMapping mappingForEntityWithName:@"MMAnswer" inManagedObjectStore:self.objectStore]; mapping.primaryKeyAttribute = @"answer_id"; [mapping mapAttributes:@"text",@"request_id",@"user_id", nil]; [mapping mapKeyPathsToAttributes: @"id", @"answer_id", nil]; [mapping mapKeyPath:@"user" toRelationship:@"user" withMapping:[self userObjectMapping]]; [mapping mapKeyPath:@"request" toRelationship:@"request" withMapping:[self requestObjectMapping]]; return mapping; } - (RKManagedObjectMapping *)requestObjectMapping { RKManagedObjectMapping *mapping = [RKManagedObjectMapping mappingForEntityWithName:@"MMRequest" inManagedObjectStore:self.objectStore]; mapping.primaryKeyAttribute = @"request_id"; [mapping mapAttributes:@"title",@"user_id", nil]; [mapping mapKeyPathsToAttributes: @"id", @"request_id", nil]; [mapping mapKeyPath:@"user" toRelationship:@"user" withMapping:[self userObjectMapping]]; return mapping; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload