Updating example project to new image request API

This commit is contained in:
Mattt Thompson 2011-09-16 22:41:21 -05:00
parent 2610b0b57a
commit 9ee84844c4
5 changed files with 76 additions and 27 deletions

View file

@ -58,6 +58,7 @@
F874B5D613E0AA6500B28E3E /* AFRestClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = AFRestClient.h; path = ../AFNetworking/AFRestClient.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; F874B5D613E0AA6500B28E3E /* AFRestClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = AFRestClient.h; path = ../AFNetworking/AFRestClient.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
F874B5D713E0AA6500B28E3E /* UIImage+AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIImage+AFNetworking.h"; path = "../AFNetworking/UIImage+AFNetworking.h"; sourceTree = "<group>"; }; F874B5D713E0AA6500B28E3E /* UIImage+AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIImage+AFNetworking.h"; path = "../AFNetworking/UIImage+AFNetworking.h"; sourceTree = "<group>"; };
F874B5D813E0AA6500B28E3E /* UIImageView+AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIImageView+AFNetworking.h"; path = "../AFNetworking/UIImageView+AFNetworking.h"; sourceTree = "<group>"; }; F874B5D813E0AA6500B28E3E /* UIImageView+AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIImageView+AFNetworking.h"; path = "../AFNetworking/UIImageView+AFNetworking.h"; sourceTree = "<group>"; };
F8870C3D1424409800BCD863 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
F8D25D101396A9C400CF3BD6 /* JSONKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSONKit.h; sourceTree = "<group>"; }; F8D25D101396A9C400CF3BD6 /* JSONKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSONKit.h; sourceTree = "<group>"; };
F8D25D111396A9C400CF3BD6 /* JSONKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSONKit.m; sourceTree = "<group>"; }; F8D25D111396A9C400CF3BD6 /* JSONKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSONKit.m; sourceTree = "<group>"; };
F8D25D131396A9C400CF3BD6 /* TTTLocationFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TTTLocationFormatter.h; sourceTree = "<group>"; }; F8D25D131396A9C400CF3BD6 /* TTTLocationFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TTTLocationFormatter.h; sourceTree = "<group>"; };
@ -174,6 +175,7 @@
F8E469551395739C00DB05C8 = { F8E469551395739C00DB05C8 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
F8870C3D1424409800BCD863 /* QuartzCore.framework */,
F8E469B71395759C00DB05C8 /* Networking Extensions */, F8E469B71395759C00DB05C8 /* Networking Extensions */,
F8E4696A1395739D00DB05C8 /* Classes */, F8E4696A1395739D00DB05C8 /* Classes */,
F8E469ED1395812A00DB05C8 /* Images */, F8E469ED1395812A00DB05C8 /* Images */,

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
version = "1.3"> version = "1.8">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"> buildImplicitDependencies = "YES">
@ -36,7 +36,9 @@
displayScale = "1.00" displayScale = "1.00"
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"> buildConfiguration = "Debug"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable> <BuildableProductRunnable>
<BuildableReference <BuildableReference
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
@ -47,6 +49,11 @@
</BuildableReference> </BuildableReference>
</BuildableProductRunnable> </BuildableProductRunnable>
<AdditionalOptions> <AdditionalOptions>
<AdditionalOption
key = "NSZombieEnabled"
value = "YES"
isEnabled = "YES">
</AdditionalOption>
</AdditionalOptions> </AdditionalOptions>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction
@ -55,7 +62,8 @@
shouldUseLaunchSchemeArgsEnv = "YES" shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = "" savedToolIdentifier = ""
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"> buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable> <BuildableProductRunnable>
<BuildableReference <BuildableReference
BuildableIdentifier = "primary" BuildableIdentifier = "primary"

View file

@ -154,18 +154,20 @@
cell = [[[SpotTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; cell = [[[SpotTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
} }
Spot *spot = [self.nearbySpots objectAtIndex:indexPath.row];
static TTTLocationFormatter *_locationFormatter = nil; static TTTLocationFormatter *_locationFormatter = nil;
if (!_locationFormatter) { if (!_locationFormatter) {
_locationFormatter = [[TTTLocationFormatter alloc] init]; _locationFormatter = [[TTTLocationFormatter alloc] init];
[_locationFormatter setUnitSystem:TTTImperialSystem]; [_locationFormatter setUnitSystem:TTTImperialSystem];
} }
Spot *spot = [self.nearbySpots objectAtIndex:indexPath.row];
cell.textLabel.text = spot.name;
if (self.locationManager.location) { if (self.locationManager.location) {
cell.detailTextLabel.text = [_locationFormatter stringFromDistanceAndBearingFromLocation:self.locationManager.location toLocation:spot.location]; cell.detailTextLabel.text = [_locationFormatter stringFromDistanceAndBearingFromLocation:self.locationManager.location toLocation:spot.location];
} }
[cell.imageView setImageWithURL:[NSURL URLWithString:spot.imageURLString] placeholderImage:[UIImage imageNamed:@"placeholder-stamp.png"]];
cell.spot = spot;
return cell; return cell;
} }

View file

@ -22,6 +22,10 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@class Spot;
@interface SpotTableViewCell : UITableViewCell @interface SpotTableViewCell : UITableViewCell
@property (nonatomic, retain) Spot *spot;
@end @end

View file

@ -22,7 +22,12 @@
#import "SpotTableViewCell.h" #import "SpotTableViewCell.h"
#import "Spot.h"
#import "UIImageView+AFNetworking.h"
@implementation SpotTableViewCell @implementation SpotTableViewCell
@synthesize spot = _spot;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
@ -32,35 +37,63 @@
self.textLabel.textColor = [UIColor darkGrayColor]; self.textLabel.textColor = [UIColor darkGrayColor];
self.textLabel.numberOfLines = 2; self.textLabel.numberOfLines = 2;
self.textLabel.backgroundColor = self.backgroundColor;
self.detailTextLabel.textColor = [UIColor grayColor]; self.detailTextLabel.textColor = [UIColor grayColor];
self.detailTextLabel.backgroundColor = self.backgroundColor;
self.imageView.backgroundColor = self.backgroundColor;
self.selectionStyle = UITableViewCellSelectionStyleGray; self.selectionStyle = UITableViewCellSelectionStyleGray;
return self; return self;
} }
#pragma mark - UIView - (void)dealloc {
[_spot release];
- (void)layoutSubviews { [super dealloc];
[super layoutSubviews];
CGRect imageViewFrame = self.imageView.frame;
CGRect textLabelFrame = self.textLabel.frame;
CGRect detailTextLabelFrame = self.detailTextLabel.frame;
imageViewFrame.origin = CGPointMake(10.0f, 10.0f);
imageViewFrame.size = CGSizeMake(50.0f, 50.0f);
textLabelFrame.origin.x = imageViewFrame.size.width + 25.0f;
detailTextLabelFrame.origin.x = textLabelFrame.origin.x;
textLabelFrame.size.width = 240.0f;
detailTextLabelFrame.size.width = textLabelFrame.size.width;
self.textLabel.frame = textLabelFrame;
self.detailTextLabel.frame = detailTextLabelFrame;
self.imageView.frame = imageViewFrame;
} }
- (void)setSpot:(Spot *)spot {
[self willChangeValueForKey:@"spot"];
[_spot autorelease];
_spot = [spot retain];
[self didChangeValueForKey:@"spot"];
[self.imageView setImageWithURL:[NSURL URLWithString:self.spot.imageURLString] placeholderImage:[UIImage imageNamed:@"placeholder-stamp.png"]];
self.textLabel.text = spot.name;
}
#pragma mark - UITableViewCell
- (void)prepareForReuse {
[self.imageView cancelImageRequestOperation];
self.textLabel.text = nil;
self.detailTextLabel.text = nil;
}
#pragma mark - UIView
//- (void)layoutSubviews {
// [super layoutSubviews];
//
// CGRect imageViewFrame = self.imageView.frame;
// CGRect textLabelFrame = self.textLabel.frame;
// CGRect detailTextLabelFrame = self.detailTextLabel.frame;
//
// imageViewFrame.origin = CGPointMake(10.0f, 10.0f);
// imageViewFrame.size = CGSizeMake(50.0f, 50.0f);
//
// textLabelFrame.origin.x = imageViewFrame.size.width + 25.0f;
// detailTextLabelFrame.origin.x = textLabelFrame.origin.x;
//
// textLabelFrame.size.width = 240.0f;
// detailTextLabelFrame.size.width = textLabelFrame.size.width;
//
// self.textLabel.frame = textLabelFrame;
// self.detailTextLabel.frame = detailTextLabelFrame;
// self.imageView.frame = CGRectIntegral(imageViewFrame);
//}
@end @end