mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-07 17:47:46 +08:00
* Cleaned up remaining warnings about if (self = [super init]) * RKParamsExample - Highlights multi-part uploads * RKRequestQueueExample - Working with the request queue * RKBackgroundRequestExample - Examples of using the background policies for backgrounding requests * RKReachabilityExample - Shows how to work with the reachability observer * RKRelationshipMappingExample - Shows how to map related objects from JSON into an object graph * RKCoreDataExample - Shows the basics of using RestKit's Core Data examples Also rearranged dispatch of RKRequest delegate method for didStartLoad: to ensure requeue callbacks get invoked in a timely manner. refs #62
79 lines
2.6 KiB
Objective-C
79 lines
2.6 KiB
Objective-C
//
|
|
// RootViewController.m
|
|
// RKCatalog
|
|
//
|
|
// Created by Blake Watters on 4/21/11.
|
|
// Copyright 2011 Two Toasters. All rights reserved.
|
|
//
|
|
|
|
#import <RestKit/RestKit.h>
|
|
#import "RootViewController.h"
|
|
|
|
@implementation RootViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
_exampleTableItems = [[NSArray alloc] initWithObjects:
|
|
@"RKParamsExample",
|
|
@"RKRequestQueueExample",
|
|
@"RKReachabilityExample",
|
|
@"RKBackgroundRequestExample",
|
|
@"RKKeyValueMappingExample",
|
|
@"RKRelationshipMappingExample",
|
|
@"RKCoreDataExample",
|
|
nil];
|
|
}
|
|
|
|
- (void)dealloc {
|
|
[_exampleTableItems release];
|
|
|
|
[super dealloc];
|
|
}
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
return 1;
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
return [_exampleTableItems count];
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
static NSString *cellIdentifier = @"RKCatalogCellIdentifier";
|
|
|
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
|
|
if (cell == nil) {
|
|
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
|
|
cell.textLabel.font = [UIFont boldSystemFontOfSize:16];
|
|
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
|
}
|
|
|
|
NSString* exampleName = [_exampleTableItems objectAtIndex:indexPath.row];
|
|
cell.textLabel.text = exampleName;
|
|
|
|
return cell;
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
// Clear the singleton instances to isolate the examples
|
|
[RKClient setSharedClient:nil];
|
|
[RKObjectManager setSharedManager:nil];
|
|
[RKRequestQueue setSharedQueue:nil];
|
|
|
|
NSString* exampleName = [_exampleTableItems objectAtIndex:indexPath.row];
|
|
Class exampleClass = NSClassFromString(exampleName);
|
|
UIViewController* exampleController = [[exampleClass alloc] initWithNibName:exampleName bundle:nil];
|
|
if (exampleController) {
|
|
[self.navigationController pushViewController:exampleController animated:YES];
|
|
if (exampleController.title == nil) {
|
|
exampleController.title = exampleName;
|
|
}
|
|
[exampleController release];
|
|
}
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
}
|
|
|
|
@end
|