Skip to content

Commit 02a1447

Browse files
committed
works!
1 parent b53a848 commit 02a1447

File tree

9 files changed

+166
-5
lines changed

9 files changed

+166
-5
lines changed

Demo/Demo.xcodeproj/project.pbxproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
4523F24F13B71DA100C883E5 /* VCResponseFetcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 4523F24713B71DA100C883E5 /* VCResponseFetcher.m */; };
2424
4523F25013B71DA100C883E5 /* VCResponseFetchService.m in Sources */ = {isa = PBXBuildFile; fileRef = 4523F24913B71DA100C883E5 /* VCResponseFetchService.m */; };
2525
4523F25113B71DA100C883E5 /* VCResponseFetchServiceCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 4523F24B13B71DA100C883E5 /* VCResponseFetchServiceCache.m */; };
26+
45B7620813B7258A005ACEA1 /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 45B7620713B7258A005ACEA1 /* RootViewController.m */; };
27+
45B7622813B7280D005ACEA1 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 45B7622713B7280D005ACEA1 /* Icon.png */; };
2628
/* End PBXBuildFile section */
2729

2830
/* Begin PBXFileReference section */
@@ -56,6 +58,9 @@
5658
4523F24A13B71DA100C883E5 /* VCResponseFetchServiceCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VCResponseFetchServiceCache.h; sourceTree = "<group>"; };
5759
4523F24B13B71DA100C883E5 /* VCResponseFetchServiceCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VCResponseFetchServiceCache.m; sourceTree = "<group>"; };
5860
4523F24C13B71DA100C883E5 /* VCResponseFetchServiceDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VCResponseFetchServiceDelegate.h; sourceTree = "<group>"; };
61+
45B7620613B7258A005ACEA1 /* RootViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RootViewController.h; sourceTree = "<group>"; };
62+
45B7620713B7258A005ACEA1 /* RootViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RootViewController.m; sourceTree = "<group>"; };
63+
45B7622713B7280D005ACEA1 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = "<group>"; };
5964
/* End PBXFileReference section */
6065

6166
/* Begin PBXFrameworksBuildPhase section */
@@ -107,10 +112,13 @@
107112
4523F24013B71DA100C883E5 /* VCResponseFetcher */,
108113
4523F23913B7196700C883E5 /* VCImageView */,
109114
4523F23313B7182600C883E5 /* VCThumbnailGridView */,
115+
45B7620613B7258A005ACEA1 /* RootViewController.h */,
116+
45B7620713B7258A005ACEA1 /* RootViewController.m */,
110117
4523F22813B7181900C883E5 /* DemoAppDelegate.h */,
111118
4523F22913B7181900C883E5 /* DemoAppDelegate.m */,
112119
4523F22B13B7181900C883E5 /* MainWindow.xib */,
113120
4523F22013B7181900C883E5 /* Supporting Files */,
121+
45B7622613B7280D005ACEA1 /* Resources */,
114122
);
115123
path = Demo;
116124
sourceTree = "<group>";
@@ -168,6 +176,14 @@
168176
path = ../../VCResponseFetcher/VCResponseFetcher;
169177
sourceTree = "<group>";
170178
};
179+
45B7622613B7280D005ACEA1 /* Resources */ = {
180+
isa = PBXGroup;
181+
children = (
182+
45B7622713B7280D005ACEA1 /* Icon.png */,
183+
);
184+
path = Resources;
185+
sourceTree = "<group>";
186+
};
171187
/* End PBXGroup section */
172188

173189
/* Begin PBXNativeTarget section */
@@ -220,6 +236,7 @@
220236
files = (
221237
4523F22413B7181900C883E5 /* InfoPlist.strings in Resources */,
222238
4523F22D13B7181900C883E5 /* MainWindow.xib in Resources */,
239+
45B7622813B7280D005ACEA1 /* Icon.png in Resources */,
223240
);
224241
runOnlyForDeploymentPostprocessing = 0;
225242
};
@@ -240,6 +257,7 @@
240257
4523F24F13B71DA100C883E5 /* VCResponseFetcher.m in Sources */,
241258
4523F25013B71DA100C883E5 /* VCResponseFetchService.m in Sources */,
242259
4523F25113B71DA100C883E5 /* VCResponseFetchServiceCache.m in Sources */,
260+
45B7620813B7258A005ACEA1 /* RootViewController.m in Sources */,
243261
);
244262
runOnlyForDeploymentPostprocessing = 0;
245263
};
@@ -344,6 +362,7 @@
344362
4523F23213B7181900C883E5 /* Release */,
345363
);
346364
defaultConfigurationIsVisible = 0;
365+
defaultConfigurationName = Release;
347366
};
348367
/* End XCConfigurationList section */
349368
};

Demo/Demo/DemoAppDelegate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
}
1414

1515
@property (nonatomic, retain) IBOutlet UIWindow *window;
16+
@property (nonatomic, retain) UINavigationController *navigationController;
1617

1718
@end

Demo/Demo/DemoAppDelegate.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@
88

99
#import "DemoAppDelegate.h"
1010

11+
#import "RootViewController.h"
12+
1113
@implementation DemoAppDelegate
1214

1315

14-
@synthesize window=_window;
16+
@synthesize window=_window, navigationController=_navigationController;
1517

1618
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
1719
{
20+
RootViewController *rootVC = [[[RootViewController alloc] init] autorelease];
21+
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:rootVC] autorelease];
22+
1823
// Override point for customization after application launch.
24+
[self.window addSubview:self.navigationController.view];
1925
[self.window makeKeyAndVisible];
2026
return YES;
2127
}
@@ -61,6 +67,7 @@ - (void)applicationWillTerminate:(UIApplication *)application
6167

6268
- (void)dealloc
6369
{
70+
[_navigationController release];
6471
[_window release];
6572
[super dealloc];
6673
}

Demo/Demo/Resources/Icon.png

15.1 KB
Loading

Demo/Demo/RootViewController.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// RootViewController.h
3+
// Demo
4+
//
5+
// Created by Vinay Chavan on 26/06/11.
6+
// Copyright 2011 Vinay Chavan. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
#import "VCThumbnailGridView.h"
12+
13+
@interface RootViewController : UIViewController <VCThumbnailGridViewDataSource, VCThumbnailGridViewDelegate> {
14+
VCThumbnailGridView *_gridView;
15+
}
16+
17+
@end

Demo/Demo/RootViewController.m

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//
2+
// RootViewController.m
3+
// Demo
4+
//
5+
// Created by Vinay Chavan on 26/06/11.
6+
// Copyright 2011 Vinay Chavan. All rights reserved.
7+
//
8+
9+
#import "RootViewController.h"
10+
11+
12+
@implementation RootViewController
13+
14+
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
15+
{
16+
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
17+
if (self) {
18+
// Custom initialization
19+
}
20+
return self;
21+
}
22+
23+
- (void)dealloc
24+
{
25+
[_gridView release];
26+
[super dealloc];
27+
}
28+
29+
- (void)didReceiveMemoryWarning
30+
{
31+
// Releases the view if it doesn't have a superview.
32+
[super didReceiveMemoryWarning];
33+
34+
// Release any cached data, images, etc that aren't in use.
35+
}
36+
37+
#pragma mark - View lifecycle
38+
39+
40+
// Implement loadView to create a view hierarchy programmatically, without using a nib.
41+
- (void)loadView
42+
{
43+
[super loadView];
44+
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
45+
self.view.backgroundColor = [UIColor blackColor];
46+
47+
_gridView = [[VCThumbnailGridView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.bounds.size.height)];
48+
_gridView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
49+
_gridView.backgroundColor = [UIColor whiteColor];
50+
_gridView.gridDelegate = self;
51+
_gridView.gridDataSource = self;
52+
_gridView.rowHeight = 150;
53+
_gridView.scrollsToTop = YES;
54+
[self.view addSubview:_gridView];
55+
}
56+
57+
58+
/*
59+
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
60+
- (void)viewDidLoad
61+
{
62+
[super viewDidLoad];
63+
}
64+
*/
65+
66+
- (void)viewDidUnload
67+
{
68+
[super viewDidUnload];
69+
// Release any retained subviews of the main view.
70+
// e.g. self.myOutlet = nil;
71+
}
72+
73+
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
74+
{
75+
// Return YES for supported orientations
76+
return (interfaceOrientation == UIInterfaceOrientationPortrait);
77+
}
78+
79+
80+
81+
#pragma mark - VCThumbnailGridViewDataSource
82+
83+
- (NSInteger)numberOfThumbnailsInThumbnailGridView:(VCThumbnailGridView*)thumbnailGridView {
84+
return 20;
85+
}
86+
- (NSInteger)numberOfThumbnailsInRowInThumbnailGridView:(VCThumbnailGridView*)thumbnailGridView {
87+
return 4;
88+
}
89+
- (UIImage*)thumbnailGridView:(VCThumbnailGridView*)thumbnailGridView imageAtIndex:(NSInteger)index {
90+
return [UIImage imageNamed:@"Icon.png"];
91+
}
92+
93+
#pragma mark - VCThumbnailGridViewDelegate
94+
95+
- (void)thumbnailGridView:(VCThumbnailGridView*)thumbnailGridView didSelectThumbnailAtIndex:(NSInteger)index {
96+
97+
}
98+
99+
@end

VCImageView/VCImageView.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
#import <UIKit/UIKit.h>
1010

11-
@interface VCImageView : UIImageView {
11+
#import "VCResponseFetcher.h"
12+
13+
@interface VCImageView : UIImageView <VCResponseFetchServiceDelegate> {
1214
UIActivityIndicatorView *activityIndicator;
1315
BOOL shouldShowActivityIndicator;
1416
BOOL shouldAutoRotateToFit;

VCImageView/VCImageView.m

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ - (void)didTapSelf:(id)sender {
6161

6262
#pragma mark - Public Methods
6363

64-
- (void)setRemoteImageUrl:(NSString*)url {
64+
- (void)setImageUrl:(NSString*)url {
65+
[[VCResponseFetcher sharedInstance] addObserver:self
66+
url:url
67+
responseOfClass:[VCImageResponseProcessor class]];
6568

6669
if (shouldShowActivityIndicator) {
6770
if (!activityIndicator) {
@@ -89,5 +92,18 @@ - (void)addTarget:(id)target withSelector:(SEL)selector {
8992
}
9093

9194

95+
#pragma mark - VCResponseFetchServiceDelegate Methods
96+
97+
-(void)didSucceedReceiveResponse:(NSObject<VCDataProcessorDelegate> *)response {
98+
if ([response isKindOfClass:[VCImageResponseProcessor class]]) {
99+
UIImage *image = [(VCImageResponseProcessor*)response image];
100+
self.image = image;
101+
}
102+
}
103+
104+
-(void)didFailReceiveResponse:(NSObject<VCDataProcessorDelegate> *)response {
105+
106+
}
107+
92108

93109
@end

VCThumbnailGridView/VCThumbnailGridView.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ - (void)createGrid {
194194
imageView.image = image;
195195
}
196196
if (imageUrl) {
197-
[imageView setRemoteImageUrl:imageUrl];
197+
[imageView setImageUrl:imageUrl];
198198
}
199199

200200
[imageView release], imageView = nil;
@@ -246,7 +246,7 @@ - (void)createStripe {
246246
imageView.image = [self.gridDataSource thumbnailGridView:self imageAtIndex:counter];
247247
}
248248
if ([self.gridDataSource respondsToSelector:@selector(thumbnailGridView:imageUrlAtIndex:)]) {
249-
[imageView setRemoteImageUrl:[self.gridDataSource thumbnailGridView:self imageUrlAtIndex:counter]];
249+
[imageView setImageUrl:[self.gridDataSource thumbnailGridView:self imageUrlAtIndex:counter]];
250250
}
251251
// add to the view
252252
[_thumbnails addObject:imageView];

0 commit comments

Comments
 (0)