Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New example added, demonstrating the use of EasyTableView with public…
… images remotely loaded from Flickr.
- Loading branch information
Aleksey Novicov
committed
Jan 31, 2012
1 parent
27a8852
commit dc67a7b
Showing
12 changed files
with
805 additions
and
513 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
// | |||
// FlipsideViewController.h | |||
// EasyTableView | |||
// | |||
// Created by Aleksey Novicov on 1/30/12. | |||
// Copyright (c) 2012 Yodel Code LLC. All rights reserved. | |||
// | |||
// Demonstrates the use of EasyTableView with images loaded from a remote server | |||
|
|||
#import <UIKit/UIKit.h> | |||
#import "EasyTableView.h" | |||
#import "ImageStore.h" | |||
|
|||
@class FlipsideViewController; | |||
|
|||
@protocol FlipsideViewControllerDelegate | |||
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller; | |||
@end | |||
|
|||
@interface FlipsideViewController : UIViewController <EasyTableViewDelegate, ImageStoreDelegate> | |||
|
|||
@property (assign, nonatomic) IBOutlet id<FlipsideViewControllerDelegate> delegate; | |||
@property (retain, nonatomic) IBOutlet UILabel *errorLabel; | |||
@property (retain, nonatomic) ImageStore *imageStore; | |||
@property (retain, nonatomic) EasyTableView *easyTableView; | |||
|
|||
- (IBAction)done:(id)sender; | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,153 @@ | |||
// | |||
// FlipsideViewController.m | |||
// EasyTableView | |||
// | |||
// Created by Aleksey Novicov on 1/30/12. | |||
// Copyright (c) 2012 Yodel Code LLC. All rights reserved. | |||
// | |||
// Demonstrates the use of EasyTableView with images loaded from a remote server | |||
|
|||
#import "FlipsideViewController.h" | |||
|
|||
#define TABLEVIEW_HEIGHT 140 | |||
#define TABLECELL_WIDTH 180 | |||
|
|||
#define LABEL_TAG 100 | |||
#define IMAGE_TAG 101 | |||
|
|||
@implementation FlipsideViewController | |||
|
|||
@synthesize delegate = _delegate; | |||
@synthesize imageStore = _imageStore; | |||
@synthesize easyTableView = _easyTableView; | |||
@synthesize errorLabel = _errorLabel; | |||
|
|||
- (void)dealloc { | |||
[_imageStore release]; | |||
[_easyTableView release]; | |||
[_errorLabel release]; | |||
|
|||
[super dealloc]; | |||
} | |||
|
|||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { | |||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | |||
if (self) { | |||
ImageStore *store = [[ImageStore alloc] initWithDelegate:self]; | |||
|
|||
self.imageStore = store; | |||
[store release]; | |||
} | |||
return self; | |||
} | |||
|
|||
- (void)didReceiveMemoryWarning { | |||
[super didReceiveMemoryWarning]; | |||
|
|||
[self.imageStore clearImageCache]; | |||
} | |||
|
|||
#pragma mark - View lifecycle | |||
|
|||
- (void)viewDidLoad { | |||
[super viewDidLoad]; | |||
// Do any additional setup after loading the view, typically from a nib. | |||
} | |||
|
|||
- (void)viewDidUnload { | |||
[super viewDidUnload]; | |||
|
|||
self.errorLabel = nil; | |||
} | |||
|
|||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | |||
return YES; | |||
} | |||
|
|||
#pragma mark - | |||
#pragma mark EasyTableView Initialization | |||
|
|||
- (void)setupEasyTableViewWithNumCells:(NSUInteger)count { | |||
CGRect frameRect = CGRectMake(0, 44, self.view.bounds.size.width, TABLEVIEW_HEIGHT); | |||
EasyTableView *view = [[EasyTableView alloc] initWithFrame:frameRect numberOfColumns:count ofWidth:TABLECELL_WIDTH]; | |||
self.easyTableView = view; | |||
|
|||
self.easyTableView.delegate = self; | |||
self.easyTableView.tableView.backgroundColor = [UIColor clearColor]; | |||
self.easyTableView.tableView.separatorColor = [UIColor blackColor]; | |||
self.easyTableView.cellBackgroundColor = [UIColor blackColor]; | |||
self.easyTableView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth; | |||
|
|||
[self.view addSubview:self.easyTableView]; | |||
[view release]; | |||
} | |||
|
|||
#pragma mark - EasyTableViewDelegate | |||
|
|||
- (UIView *)easyTableView:(EasyTableView *)easyTableView viewForRect:(CGRect)rect { | |||
UIView *container = [[[UIView alloc] initWithFrame:rect] autorelease];; | |||
|
|||
// Setup an image view to display an image | |||
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(1, 0, rect.size.width-2, rect.size.height)]; | |||
imageView.tag = IMAGE_TAG; | |||
imageView.contentMode = UIViewContentModeScaleAspectFill; | |||
|
|||
[container addSubview:imageView]; | |||
[imageView release]; | |||
|
|||
// Setup a label to display the image title | |||
CGRect labelRect = CGRectMake(10, rect.size.height-20, rect.size.width-20, 20); | |||
UILabel *label = [[UILabel alloc] initWithFrame:labelRect]; | |||
label.textAlignment = UITextAlignmentCenter; | |||
label.textColor = [UIColor colorWithWhite:1.0 alpha:0.5]; | |||
label.backgroundColor = [UIColor clearColor]; | |||
label.font = [UIFont boldSystemFontOfSize:14]; | |||
label.tag = LABEL_TAG; | |||
|
|||
[container addSubview:label]; | |||
[label release]; | |||
|
|||
return container; | |||
} | |||
|
|||
// Second delegate populates the views with data from a data source | |||
|
|||
- (void)easyTableView:(EasyTableView *)easyTableView setDataForView:(UIView *)view forIndex:(NSUInteger)index { | |||
// Set the image title for the given index | |||
UILabel *label = (UILabel *)[view viewWithTag:LABEL_TAG]; | |||
label.text = [self.imageStore.titles objectAtIndex:index]; | |||
|
|||
// Set the image for the given index | |||
UIImageView *imageView = (UIImageView *)[view viewWithTag:IMAGE_TAG]; | |||
imageView.image = [self.imageStore imageAtIndex:index]; | |||
} | |||
|
|||
#pragma mark - ImageStoreDelegate | |||
|
|||
- (void)imageTitles:(NSArray *)titles { | |||
[self setupEasyTableViewWithNumCells:[titles count]]; | |||
} | |||
|
|||
- (void)errorMessage:(NSString *)message { | |||
self.errorLabel.text = message; | |||
} | |||
|
|||
- (void)image:(UIImage *)image loadedAtIndex:(NSUInteger)index { | |||
UIView *view = [self.easyTableView viewAtIndex:index]; | |||
|
|||
// The view might be nil if the cell has scrolled offscreen while we were waiting for the image to load. | |||
// In that case, there is no need to set the image, nor is it even possible. | |||
if (view) { | |||
// Set the image for the view (cell) | |||
UIImageView *imageView = (UIImageView *)[view viewWithTag:IMAGE_TAG]; | |||
imageView.image = image; | |||
} | |||
} | |||
|
|||
#pragma mark - Actions | |||
|
|||
- (IBAction)done:(id)sender { | |||
[self.delegate flipsideViewControllerDidFinish:self]; | |||
} | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
// | |||
// ImageStore.h | |||
// EasyTableView | |||
// | |||
// Created by Aleksey Novicov on 1/30/12. | |||
// Copyright (c) 2012 Yodel Code LLC. All rights reserved. | |||
// | |||
// This class loads the most recently added public Flickr images. | |||
|
|||
#import <Foundation/Foundation.h> | |||
|
|||
@protocol ImageStoreDelegate <NSObject> | |||
- (void)imageTitles:(NSArray *)titles; | |||
- (void)errorMessage:(NSString *)message; | |||
- (void)image:(UIImage *)image loadedAtIndex:(NSUInteger)index; | |||
@end | |||
|
|||
@interface ImageStore : NSObject | |||
|
|||
@property (assign, nonatomic) id<ImageStoreDelegate> delegate; | |||
@property (retain, nonatomic) NSOperationQueue *operationQueue; | |||
@property (retain, nonatomic) NSArray *titles; | |||
@property (retain, nonatomic) NSArray *urls; | |||
@property (retain, nonatomic) NSMutableDictionary *imageCache; | |||
|
|||
- (id)initWithDelegate:(id<ImageStoreDelegate>)delegate; | |||
- (UIImage *)imageAtIndex:(NSUInteger)index; | |||
- (void)clearImageCache; | |||
|
|||
@end |
Oops, something went wrong.