Skip to content

Instantly share code, notes, and snippets.

@doover
Created February 28, 2012 21:08
Show Gist options
  • Select an option

  • Save doover/1935153 to your computer and use it in GitHub Desktop.

Select an option

Save doover/1935153 to your computer and use it in GitHub Desktop.
CS193P assignment 4 "sketch"
@interface FT10PhotoTableViewController : UITableViewController
@property NSArray *photoArray;
@end
@implementation FT10PhotoTableViewController
@synthesize photoArray =_photoArray;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Photo Details";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
NSDictionary *photo =[self.photoArray objectAtIndex:[indexPath row]];
cell.textLabel.text =[photo valueForKey:@"title"];
NSString *desc =[photo valueForKeyPath:@"description._content"];
if (desc.length ==0)
desc =@"(no description)";
cell.detailTextLabel.text =desc;
NSURL *photoURL =[FlickrFetcher urlForPhoto:photo format:FlickrPhotoFormatSquare];
NSData *photoData =[NSData dataWithContentsOfURL:photoURL];
UIImage *photoImage =[UIImage imageWithData:photoData];
cell.imageView.image =photoImage;
return cell;
}
@end
@interface FT10PhotoViewController : UIViewController
@property (nonatomic, strong) UIImage *image;
@end
@interface FT10PhotoViewController () <UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation FT10PhotoViewController
@synthesize scrollView =_scrollView;
@synthesize imageView =_imageView;
@synthesize image =_image;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.imageView.image =self.image;
self.imageView.frame =(CGRect){CGPointZero, self.imageView.image.size};
self.scrollView.contentSize =self.imageView.image.size;
self.scrollView.minimumZoomScale =.1;
self.scrollView.maximumZoomScale =10;
self.scrollView.delegate =self;
self.scrollView.scrollEnabled =YES;
}
@end
@interface FT10TopPlacesTableViewController ()
@property (nonatomic, strong) NSArray *topPlaces;
@end
@implementation FT10TopPlacesTableViewController
@synthesize topPlaces =_topPlaces;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.topPlaces count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Top Place Description";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
NSDictionary *place =[self.topPlaces objectAtIndex:[indexPath row]];
NSArray *stringComponents =[place componentsSeparatedByString:@","];
cell.textLabel.text = [stringComponents objectAtIndex:0];
}
#pragma mark - Table view delegate
-(void)prepareForSegue:(UIStoryboardSegue *)segue
sender:(id)sender {
if ([segue.identifier isEqualToString:@"Place Photos"]) {
FT10PhotoTableViewController *newViewController =(FT10PhotoTableViewController *)segue.destinationViewController;
NSIndexPath *indexPath =[self.tableView indexPathForCell:sender];
NSDictionary *place =[self.topPlaces objectAtIndex:[indexPath row]];
newViewController.photoArray =[FlickrFetcher photosInPlace:place maxResults:10];
newViewController.title =[self extractPlaceName:place];
// [segue.destinationViewController setDataSource:self];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment