Removing BaseViewController

This commit is contained in:
Mattt Thompson
2011-10-31 10:20:11 -05:00
parent 12fce97205
commit 6de3863a51
20 changed files with 142 additions and 324 deletions

View File

@@ -45,7 +45,6 @@
09885EC11418F2E600CCE17A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 09885EBF1418F2E600CCE17A /* InfoPlist.strings */; };
09885EC31418F2E600CCE17A /* IOSBoilerplateTests.h in Resources */ = {isa = PBXBuildFile; fileRef = 09885EC21418F2E600CCE17A /* IOSBoilerplateTests.h */; };
09885EC51418F2E600CCE17A /* IOSBoilerplateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 09885EC41418F2E600CCE17A /* IOSBoilerplateTests.m */; };
09885EF91418F4AB00CCE17A /* BaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 09885EF81418F4AB00CCE17A /* BaseViewController.m */; };
09885F3C1418FC6F00CCE17A /* HTTPHUDExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 09885F3A1418FC6E00CCE17A /* HTTPHUDExample.m */; };
09885F3D1418FC6F00CCE17A /* HTTPHUDExample.xib in Resources */ = {isa = PBXBuildFile; fileRef = 09885F3B1418FC6E00CCE17A /* HTTPHUDExample.xib */; };
09885F421418FFE000CCE17A /* SVProgressHUD.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 09885F3F1418FFE000CCE17A /* SVProgressHUD.bundle */; };
@@ -159,8 +158,6 @@
09885EEC1418F3F900CCE17A /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
09885EEE1418F40200CCE17A /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
09885EF11418F44200CCE17A /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
09885EF71418F4AB00CCE17A /* BaseViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseViewController.h; sourceTree = "<group>"; };
09885EF81418F4AB00CCE17A /* BaseViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseViewController.m; sourceTree = "<group>"; };
09885F391418FC6E00CCE17A /* HTTPHUDExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTTPHUDExample.h; sourceTree = "<group>"; };
09885F3A1418FC6E00CCE17A /* HTTPHUDExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTTPHUDExample.m; sourceTree = "<group>"; };
09885F3B1418FC6E00CCE17A /* HTTPHUDExample.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HTTPHUDExample.xib; sourceTree = "<group>"; };
@@ -415,8 +412,6 @@
09885EF61418F48F00CCE17A /* Helpers */ = {
isa = PBXGroup;
children = (
09885EF71418F4AB00CCE17A /* BaseViewController.h */,
09885EF81418F4AB00CCE17A /* BaseViewController.m */,
09885F46141901E700CCE17A /* DictionaryHelper.h */,
09885F47141901E700CCE17A /* DictionaryHelper.m */,
09885F5714190D7900CCE17A /* FastCell.h */,
@@ -629,7 +624,6 @@
09885EA11418F2E600CCE17A /* main.m in Sources */,
09885EA51418F2E600CCE17A /* IOSBoilerplateAppDelegate.m in Sources */,
09885EAB1418F2E600CCE17A /* RootViewController.m in Sources */,
09885EF91418F4AB00CCE17A /* BaseViewController.m in Sources */,
09885F3C1418FC6F00CCE17A /* HTTPHUDExample.m in Sources */,
09885F431418FFE000CCE17A /* SVProgressHUD.m in Sources */,
09885F48141901E700CCE17A /* DictionaryHelper.m in Sources */,

View File

@@ -28,7 +28,8 @@
#import "AsyncCell.h"
#import "DictionaryHelper.h"
#import "AFImageRequestOperation.h"
#import "UIImageView+AFNetworking.h"
@implementation AsyncCell
@@ -84,15 +85,15 @@ static UIFont* bold14 = nil;
[[UIColor grayColor] set];
[text drawInRect:CGRectMake(63.0, 25.0, widthr, 20.0) withFont:system14 lineBreakMode:UILineBreakModeTailTruncation];
if (image) {
if (self.image) {
CGRect r = CGRectMake(5.0, 5.0, 48.0, 48.0);
[image drawInRect:r];
[self.image drawInRect:r];
}
}
- (void) updateCellInfo:(NSDictionary*)_info {
self.info = _info;
NSString *urlString = [info stringForKey:@"profile_image_url"];
NSString *urlString = [info stringForKey:@"profile_image_url"];
if (urlString) {
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] success:^(UIImage *requestedImage) {
self.image = requestedImage;

View File

@@ -26,9 +26,9 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#import "BaseViewController.h"
#import <UIKit/UIKit.h>
@interface AsyncCellImagesExample : BaseViewController <UITableViewDelegate, UITableViewDataSource>
@interface AsyncCellImagesExample : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain) IBOutlet UITableView* table;
@property (nonatomic, retain) NSArray* results;

View File

@@ -29,6 +29,7 @@
#import "AsyncCellImagesExample.h"
#import "SVProgressHUD.h"
#import "JSONKit.h"
#import "AFJSONRequestOperation.h"
#import "DictionaryHelper.h"
#import "AsyncCell.h"
@@ -113,18 +114,18 @@
[SVProgressHUD showInView:self.view];
NSURLRequest *request = [self requestWithURL:@"http://search.twitter.com/search.json?q=%23ios"];
[self jsonRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[SVProgressHUD dismiss];
self.results = [JSON arrayForKey:@"results"];
[table reloadData];
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
[SVProgressHUD dismissWithError:[error localizedDescription]];
}
];
NSString *urlString = @"http://search.twitter.com/search.json?q=%23ios";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[SVProgressHUD dismiss];
self.results = [JSON arrayForKey:@"results"];
[table reloadData];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
[SVProgressHUD dismissWithError:[error localizedDescription]];
}];
[operation start];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

View File

@@ -26,9 +26,9 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#import "BaseViewController.h"
#import <UIKit/UIKit.h>
@interface AsyncImageExample : BaseViewController
@interface AsyncImageExample : UIViewController
@property (nonatomic, retain) IBOutlet UIImageView* imageView;

View File

@@ -27,6 +27,7 @@
//
#import "AsyncImageExample.h"
#import "UIImageView+AFNetworking.h"
@implementation AsyncImageExample

View File

@@ -26,9 +26,9 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#import "BaseViewController.h"
#import <UIKit/UIKit.h>
@interface AutocompleteLocationExample : BaseViewController
@interface AutocompleteLocationExample : UIViewController
@property (nonatomic, retain) NSMutableArray* suggestions;
@property (nonatomic, retain) IBOutlet UILabel* label;

View File

@@ -29,6 +29,7 @@
#import "AutocompleteLocationExample.h"
#import "StringHelper.h"
#import "JSONKit.h"
#import "AFJSONRequestOperation.h"
#import <MapKit/MapKit.h>
@implementation AutocompleteLocationExample
@@ -131,47 +132,46 @@
// You could limit the search to a region (e.g. a country) by appending more text to the query
// example: query = [NSString stringWithFormat:@"%@, Spain", text];
NSString *urlEncode = [query urlEncode];
NSString* u = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&hl=%@&oe=UTF8", urlEncode, [[NSLocale currentLocale] localeIdentifier]];
NSURLRequest *request = [self requestWithURL:u];
[self jsonRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"success");
NSMutableArray* sug = [[NSMutableArray alloc] init];
NSArray* placemarks = [JSON objectForKey:@"Placemark"];
for (NSDictionary* placemark in placemarks) {
NSString* address = [placemark objectForKey:@"address"];
NSDictionary* point = [placemark objectForKey:@"Point"];
NSArray* coordinates = [point objectForKey:@"coordinates"];
NSNumber* lon = [coordinates objectAtIndex:0];
NSNumber* lat = [coordinates objectAtIndex:1];
MKPointAnnotation* place = [[MKPointAnnotation alloc] init];
place.title = address;
CLLocationCoordinate2D c = CLLocationCoordinate2DMake([lat doubleValue], [lon doubleValue]);
place.coordinate = c;
[sug addObject:place];
[place release];
}
self.suggestions = sug;
[sug release];
[self.searchDisplayController.searchResultsTableView reloadData];
loading = NO;
if (dirty) {
dirty = NO;
[self loadSearchSuggestions];
}
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"failure %@", [error localizedDescription]);
loading = NO;
}
];
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&hl=%@&oe=UTF8", urlEncode, [[NSLocale currentLocale] localeIdentifier]];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"success");
NSMutableArray* sug = [[NSMutableArray alloc] init];
NSArray* placemarks = [JSON objectForKey:@"Placemark"];
for (NSDictionary* placemark in placemarks) {
NSString* address = [placemark objectForKey:@"address"];
NSDictionary* point = [placemark objectForKey:@"Point"];
NSArray* coordinates = [point objectForKey:@"coordinates"];
NSNumber* lon = [coordinates objectAtIndex:0];
NSNumber* lat = [coordinates objectAtIndex:1];
MKPointAnnotation* place = [[MKPointAnnotation alloc] init];
place.title = address;
CLLocationCoordinate2D c = CLLocationCoordinate2DMake([lat doubleValue], [lon doubleValue]);
place.coordinate = c;
[sug addObject:place];
[place release];
}
self.suggestions = sug;
[sug release];
[self.searchDisplayController.searchResultsTableView reloadData];
loading = NO;
if (dirty) {
dirty = NO;
[self loadSearchSuggestions];
}
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"failure %@", [error localizedDescription]);
loading = NO;
}];
[operation start];
}
#pragma mark -

View File

@@ -1,63 +0,0 @@
//
// BaseViewController.h
//
// Copyright (c) 2011 Alberto Gimeno Brieba
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#import <UIKit/UIKit.h>
#import "AFJSONRequestOperation.h"
#import "AFXMLRequestOperation.h"
#import "AFImageRequestOperation.h"
#import "AFHTTPRequestOperation.h"
@interface BaseViewController : UIViewController {
NSMutableArray* requests;
NSOperationQueue *queue;
}
- (void) queueOperation:(NSOperation*)operation;
- (void) cancelOperations;
- (NSURLRequest*) requestWithURL:(NSString*)urlString;
- (NSMutableURLRequest*) mutableRequestWithURL:(NSString*)urlString;
- (AFHTTPRequestOperation *)simpleRequest:(NSURLRequest *)urlRequest
success:(void (^)(id object))success
failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure;
- (AFImageRequestOperation*) imageRequest:(NSURLRequest *)urlRequest
success:(void (^)(UIImage *image))success;
- (AFJSONRequestOperation*) jsonRequest:(NSURLRequest *)urlRequest
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
- (AFXMLRequestOperation*) xmlRequest:(NSURLRequest *)urlRequest
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
@end

View File

@@ -1,113 +0,0 @@
//
// BaseViewController.m
//
// Copyright (c) 2011 Alberto Gimeno Brieba
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#import "BaseViewController.h"
#import "IOSBoilerplateAppDelegate.h"
@implementation BaseViewController
#pragma mark -
#pragma mark HTTP requests
- (NSURLRequest*) requestWithURL:(NSString*)urlString {
return [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
}
- (NSMutableURLRequest*) mutableRequestWithURL:(NSString*)urlString {
return [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
}
- (AFImageRequestOperation*) imageRequest:(NSURLRequest *)urlRequest
success:(void (^)(UIImage *image))success {
AFImageRequestOperation* operation = [AFImageRequestOperation imageRequestOperationWithRequest:urlRequest success:success];
[self queueOperation:operation];
return operation;
}
- (AFJSONRequestOperation*) jsonRequest:(NSURLRequest *)urlRequest
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure {
AFJSONRequestOperation* operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:urlRequest success:success failure:failure];
operation.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];
[self queueOperation:operation];
return operation;
}
- (AFXMLRequestOperation*) xmlRequest:(NSURLRequest *)urlRequest
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure {
AFXMLRequestOperation* operation = [AFXMLRequestOperation XMLParserRequestOperationWithRequest:urlRequest success:success failure:failure];
[self queueOperation:operation];
return operation;
}
- (AFHTTPRequestOperation *)simpleRequest:(NSURLRequest *)urlRequest
success:(void (^)(id object))success
failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure {
AFHTTPRequestOperation* operation = [AFHTTPRequestOperation HTTPRequestOperationWithRequest:urlRequest success:success failure:failure];
[self queueOperation:operation];
return operation;
}
- (void) queueOperation:(NSOperation*)operation {
if (!queue) {
queue = [[NSOperationQueue alloc] init];
}
[queue addOperation:operation];
}
- (void) cancelOperations {
[queue cancelAllOperations];
}
#pragma mark -
#pragma mark UIViewController
- (void) viewDidLoad {
[super viewDidLoad];
}
- (void) viewDidUnload {
[super viewDidUnload];
}
#pragma mark -
#pragma mark Memory management
- (void)dealloc {
[self cancelOperations];
[requests release];
[super dealloc];
}
@end

View File

@@ -26,10 +26,9 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#import "BaseViewController.h"
#import <MapKit/MapKit.h>
@interface DirectionsExample : BaseViewController
@interface DirectionsExample : UIViewController
@property(nonatomic, retain) id<MKAnnotation> source;
@property(nonatomic, retain) id<MKAnnotation> destination;

View File

@@ -28,6 +28,7 @@
#import "DirectionsExample.h"
#import "StringHelper.h"
#import "AFHTTPRequestOperation.h"
@implementation DirectionsExample
@@ -144,50 +145,45 @@
NSString* saddr = [NSString stringWithFormat:@"%f,%f", f.latitude, f.longitude];
NSString* daddr = [NSString stringWithFormat:@"%f,%f", t.latitude, t.longitude];
NSString* s = [NSString stringWithFormat:@"http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@&hl=%@", saddr, daddr, [[NSLocale currentLocale] localeIdentifier]];
NSString* urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@&hl=%@", saddr, daddr, [[NSLocale currentLocale] localeIdentifier]];
// by car:
// s = [s stringByAppendingFormat:@"&dirflg=w"];
NSURLRequest *request = [self requestWithURL:s];
// urlString = [urlString stringByAppendingFormat:@"&dirflg=w"];
[self simpleRequest:request
success:^(id object) {
@try {
NSData* data = object;
NSString* responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// TODO: better parsing. Regular expression?
NSInteger a = [responseString indexOf:@"points:\"" from:0];
NSInteger b = [responseString indexOf:@"\",levels:\"" from:a] - 10;
NSInteger c = [responseString indexOf:@"tooltipHtml:\"" from:0];
NSInteger d = [responseString indexOf:@"(" from:c];
NSInteger e = [responseString indexOf:@")\"" from:d] - 2;
NSString* info = [[responseString substringFrom:d to:e] stringByReplacingOccurrencesOfString:@"\\x26#160;" withString:@""];
NSLog(@"tooltip %@", info);
NSString* encodedPoints = [responseString substringFrom:a to:b];
NSArray* steps = [self decodePolyLine:[encodedPoints mutableCopy]];
if (steps && [steps count] > 0) {
[self setRoutePoints:steps];
//} else if (!steps) {
// [self showError:@"No se pudo calcular la ruta"];
} else {
// TODO: show error
}
[responseString release];
}
@catch (NSException * e) {
// TODO: show error
}
}
failure:^(NSHTTPURLResponse *response, NSError *error) {
// TODO: show error
}
];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.completionBlock = ^ {
@try {
NSData* data = operation.responseData;
NSString* responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// TODO: better parsing. Regular expression?
NSInteger a = [responseString indexOf:@"points:\"" from:0];
NSInteger b = [responseString indexOf:@"\",levels:\"" from:a] - 10;
NSInteger c = [responseString indexOf:@"tooltipHtml:\"" from:0];
NSInteger d = [responseString indexOf:@"(" from:c];
NSInteger e = [responseString indexOf:@")\"" from:d] - 2;
NSString* info = [[responseString substringFrom:d to:e] stringByReplacingOccurrencesOfString:@"\\x26#160;" withString:@""];
NSLog(@"tooltip %@", info);
NSString* encodedPoints = [responseString substringFrom:a to:b];
NSArray* steps = [self decodePolyLine:[encodedPoints mutableCopy]];
if (steps && [steps count] > 0) {
[self setRoutePoints:steps];
//} else if (!steps) {
// [self showError:@"No se pudo calcular la ruta"];
} else {
// TODO: show error
}
[responseString release];
}
@catch (NSException * e) {
// TODO: show error
}
};
/*
NSString* s = [NSString stringWithFormat:@"http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@&hl=%@", saddr, daddr, [[NSLocale currentLocale] localeIdentifier]];

View File

@@ -26,10 +26,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#import "BaseViewController.h"
#import <UIKit/UIKit.h>
@interface HTTPHUDExample : BaseViewController {
@interface HTTPHUDExample : UIViewController {
NSOperationQueue *_requestOperationQueue;
}
@property (nonatomic, retain) IBOutlet UILabel* label;

View File

@@ -32,15 +32,20 @@
#import "DictionaryHelper.h"
#import "AFJSONRequestOperation.h"
@interface HTTPHUDExample ()
@property (readwrite, nonatomic, retain) NSOperationQueue *requestOperationQueue;
@end
@implementation HTTPHUDExample
@synthesize label;
@synthesize requestOperationQueue = _requestOperationQueue;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.requestOperationQueue = [[[NSOperationQueue alloc] init] autorelease];
}
return self;
}
@@ -78,17 +83,15 @@
[SVProgressHUD showInView:self.view];
NSURLRequest *request = [self requestWithURL:@"http://api.twitter.com/1/statuses/show.json?id=125372508387024896&include_entities=false"];
[self jsonRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
label.text = [JSON valueForKeyPath:@"text"];
[SVProgressHUD dismissWithSuccess:@"Ok!"];
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
label.text = @"error";
[SVProgressHUD dismissWithError:[error localizedDescription]];
}
];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/statuses/show.json?id=125372508387024896&include_entities=false"]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
label.text = [JSON valueForKeyPath:@"text"];
[SVProgressHUD dismissWithSuccess:@"Ok!"];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
label.text = @"error";
[SVProgressHUD dismissWithError:[error localizedDescription]];
}];
[operation start];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

View File

@@ -102,6 +102,7 @@
}
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
}
- (void)dealloc

View File

@@ -26,10 +26,9 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#import "BaseViewController.h"
#import "EGORefreshTableHeaderView.h"
@interface ListViewController : BaseViewController<EGORefreshTableHeaderDelegate> {
@interface ListViewController : UIViewController <EGORefreshTableHeaderDelegate> {
EGORefreshTableHeaderView *_refreshHeaderView;
BOOL _reloading;

View File

@@ -27,9 +27,8 @@
//
#import <UIKit/UIKit.h>
#import "BaseViewController.h"
@interface RootViewController : BaseViewController <UITableViewDelegate, UITableViewDataSource> {
@interface RootViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
}

View File

@@ -26,9 +26,9 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#import "BaseViewController.h"
#import <UIKit/UIKit.h>
@interface SwipeableTableViewExample : BaseViewController <UITableViewDelegate, UITableViewDataSource>
@interface SwipeableTableViewExample : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain) IBOutlet UITableView* table;

View File

@@ -26,9 +26,9 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#import "BaseViewController.h"
#import <UIKit/UIKit.h>
@interface VariableHeightExample : BaseViewController <UITableViewDelegate, UITableViewDataSource>
@interface VariableHeightExample : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain) IBOutlet UITableView* table;
@property (nonatomic, retain) NSArray* results;

View File

@@ -29,6 +29,7 @@
#import "VariableHeightExample.h"
#import "SVProgressHUD.h"
#import "JSONKit.h"
#import "AFJSONRequestOperation.h"
#import "DictionaryHelper.h"
#import "VariableHeightCell.h"
@@ -110,18 +111,17 @@
[SVProgressHUD showInView:self.view];
NSURLRequest *request = [self requestWithURL:@"http://search.twitter.com/search.json?q=%23cats"];
[self jsonRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[SVProgressHUD dismiss];
self.results = [JSON arrayForKey:@"results"];
[table reloadData];
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
[SVProgressHUD dismissWithError:[error localizedDescription]];
}
];
NSString *urlString = @"http://search.twitter.com/search.json?q=%23cats";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[SVProgressHUD dismiss];
self.results = [JSON arrayForKey:@"results"];
[table reloadData];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
[SVProgressHUD dismissWithError:[error localizedDescription]];
}];
[operation start];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {