|
| 1 | +// |
| 2 | +// MasterViewController.m |
| 3 | +// SDWebImage Demo |
| 4 | +// |
| 5 | +// Created by Olivier Poitrey on 09/05/12. |
| 6 | +// Copyright (c) 2012 Dailymotion. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "MasterViewController.h" |
| 10 | +#import <SDWebImage/UIImageView+WebCache.h> |
| 11 | +#import "DetailViewController.h" |
| 12 | + |
| 13 | +@interface MasterViewController () { |
| 14 | + NSMutableArray *_objects; |
| 15 | +} |
| 16 | +@end |
| 17 | + |
| 18 | +@implementation MasterViewController |
| 19 | + |
| 20 | +@synthesize detailViewController = _detailViewController; |
| 21 | + |
| 22 | +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil |
| 23 | +{ |
| 24 | + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; |
| 25 | + if (self) |
| 26 | + { |
| 27 | + self.title = @"SDWebImage"; |
| 28 | + _objects = [NSArray arrayWithObjects: |
| 29 | + @"http://static2.dmcdn.net/static/video/451/838/44838154:jpeg_preview_small.jpg?20120509163826", |
| 30 | + @"http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.jpg?20120509154705", |
| 31 | + @"http://static2.dmcdn.net/static/video/629/228/44822926:jpeg_preview_small.jpg?20120509181018", |
| 32 | + @"http://static2.dmcdn.net/static/video/116/367/44763611:jpeg_preview_small.jpg?20120509101749", |
| 33 | + @"http://static2.dmcdn.net/static/video/340/086/44680043:jpeg_preview_small.jpg?20120509180118", |
| 34 | + @"http://static2.dmcdn.net/static/video/666/645/43546666:jpeg_preview_small.jpg?20120412153140", |
| 35 | + @"http://static2.dmcdn.net/static/video/771/577/44775177:jpeg_preview_small.jpg?20120509183230", |
| 36 | + @"http://static2.dmcdn.net/static/video/810/508/44805018:jpeg_preview_small.jpg?20120508125339", |
| 37 | + @"http://static2.dmcdn.net/static/video/152/008/44800251:jpeg_preview_small.jpg?20120508103336", |
| 38 | + @"http://static2.dmcdn.net/static/video/694/741/35147496:jpeg_preview_small.jpg?20120508111445", |
| 39 | + @"http://static2.dmcdn.net/static/video/988/667/44766889:jpeg_preview_small.jpg?20120508130425", |
| 40 | + @"http://static2.dmcdn.net/static/video/282/467/44764282:jpeg_preview_small.jpg?20120507130637", |
| 41 | + @"http://static2.dmcdn.net/static/video/754/657/44756457:jpeg_preview_small.jpg?20120507093012", |
| 42 | + @"http://static2.dmcdn.net/static/video/831/107/44701138:jpeg_preview_small.jpg?20120506133917", |
| 43 | + @"http://static2.dmcdn.net/static/video/411/057/44750114:jpeg_preview_small.jpg?20120507014914", |
| 44 | + @"http://static2.dmcdn.net/static/video/894/547/44745498:jpeg_preview_small.jpg?20120509183004", |
| 45 | + @"http://static2.dmcdn.net/static/video/082/947/44749280:jpeg_preview_small.jpg?20120507015022", |
| 46 | + @"http://static2.dmcdn.net/static/video/833/347/44743338:jpeg_preview_small.jpg?20120509183004", |
| 47 | + @"http://static2.dmcdn.net/static/video/683/666/44666386:jpeg_preview_small.jpg?20120505111208", |
| 48 | + @"http://static2.dmcdn.net/static/video/595/946/44649595:jpeg_preview_small.jpg?20120507194104", |
| 49 | + @"http://static2.dmcdn.net/static/video/984/935/44539489:jpeg_preview_small.jpg?20120501184650", |
| 50 | + @"http://static2.dmcdn.net/static/video/440/416/44614044:jpeg_preview_small.jpg?20120505174152", |
| 51 | + @"http://static2.dmcdn.net/static/video/561/977/20779165:jpeg_preview_small.jpg?20120423161805", |
| 52 | + @"http://static2.dmcdn.net/static/video/104/546/44645401:jpeg_preview_small.jpg?20120507185246", |
| 53 | + @"http://static2.dmcdn.net/static/video/671/636/44636176:jpeg_preview_small.jpg?20120504021339", |
| 54 | + @"http://static2.dmcdn.net/static/video/142/746/44647241:jpeg_preview_small.jpg?20120504104451", |
| 55 | + @"http://static2.dmcdn.net/static/video/776/860/44068677:jpeg_preview_small.jpg?20120507185251", |
| 56 | + @"http://static2.dmcdn.net/static/video/026/626/44626620:jpeg_preview_small.jpg?20120503203036", |
| 57 | + @"http://static2.dmcdn.net/static/video/364/663/39366463:jpeg_preview_small.jpg?20120509163505", |
| 58 | + @"http://static2.dmcdn.net/static/video/392/895/44598293:jpeg_preview_small.jpg?20120503165252", |
| 59 | + @"http://static2.dmcdn.net/static/video/620/865/44568026:jpeg_preview_small.jpg?20120507185121", |
| 60 | + @"http://static2.dmcdn.net/static/video/031/395/44593130:jpeg_preview_small.jpg?20120507185139", |
| 61 | + @"http://static2.dmcdn.net/static/video/676/495/44594676:jpeg_preview_small.jpg?20120503121341", |
| 62 | + @"http://static2.dmcdn.net/static/video/025/195/44591520:jpeg_preview_small.jpg?20120503132132", |
| 63 | + @"http://static2.dmcdn.net/static/video/993/665/44566399:jpeg_preview_small.jpg?20120503182623", |
| 64 | + @"http://static2.dmcdn.net/static/video/137/635/44536731:jpeg_preview_small.jpg?20120501165940", |
| 65 | + @"http://static2.dmcdn.net/static/video/611/794/44497116:jpeg_preview_small.jpg?20120507184954", |
| 66 | + @"http://static2.dmcdn.net/static/video/732/790/44097237:jpeg_preview_small.jpg?20120430162348", |
| 67 | + @"http://static2.dmcdn.net/static/video/064/991/44199460:jpeg_preview_small.jpg?20120430101250", |
| 68 | + @"http://static2.dmcdn.net/static/video/404/094/44490404:jpeg_preview_small.jpg?20120507184948", |
| 69 | + @"http://static2.dmcdn.net/static/video/413/120/44021314:jpeg_preview_small.jpg?20120507180850", |
| 70 | + @"http://static2.dmcdn.net/static/video/200/584/44485002:jpeg_preview_small.jpg?20120507184941", |
| 71 | + @"http://static2.dmcdn.net/static/video/551/318/42813155:jpeg_preview_small.jpg?20120412153202", |
| 72 | + @"http://static2.dmcdn.net/static/video/524/750/44057425:jpeg_preview_small.jpg?20120501220912", |
| 73 | + @"http://static2.dmcdn.net/static/video/124/843/44348421:jpeg_preview_small.jpg?20120507184551", |
| 74 | + @"http://static2.dmcdn.net/static/video/496/394/42493694:jpeg_preview_small.jpg?20120430105337", |
| 75 | + @"http://static2.dmcdn.net/static/video/548/883/44388845:jpeg_preview_small.jpg?20120428212713", |
| 76 | + @"http://static2.dmcdn.net/static/video/282/533/44335282:jpeg_preview_small.jpg?20120427102844", |
| 77 | + @"http://static2.dmcdn.net/static/video/257/132/44231752:jpeg_preview_small.jpg?20120428212609", |
| 78 | + @"http://static2.dmcdn.net/static/video/480/193/44391084:jpeg_preview_small.jpg?20120501143214", |
| 79 | + @"http://static2.dmcdn.net/static/video/903/432/44234309:jpeg_preview_small.jpg?20120427200002", |
| 80 | + @"http://static2.dmcdn.net/static/video/646/573/44375646:jpeg_preview_small.jpg?20120507184652", |
| 81 | + @"http://static2.dmcdn.net/static/video/709/573/44375907:jpeg_preview_small.jpg?20120507184652", |
| 82 | + @"http://static2.dmcdn.net/static/video/885/633/44336588:jpeg_preview_small.jpg?20120507184540", |
| 83 | + @"http://static2.dmcdn.net/static/video/732/523/44325237:jpeg_preview_small.jpg?20120426110308", |
| 84 | + @"http://static2.dmcdn.net/static/video/935/132/44231539:jpeg_preview_small.jpg?20120426115744", |
| 85 | + @"http://static2.dmcdn.net/static/video/941/129/43921149:jpeg_preview_small.jpg?20120426094640", |
| 86 | + @"http://static2.dmcdn.net/static/video/775/942/44249577:jpeg_preview_small.jpg?20120425011228", |
| 87 | + @"http://static2.dmcdn.net/static/video/868/332/44233868:jpeg_preview_small.jpg?20120429152901", |
| 88 | + @"http://static2.dmcdn.net/static/video/959/732/44237959:jpeg_preview_small.jpg?20120425133534", |
| 89 | + @"http://static2.dmcdn.net/static/video/383/402/44204383:jpeg_preview_small.jpg?20120424185842", |
| 90 | + @"http://static2.dmcdn.net/static/video/971/932/44239179:jpeg_preview_small.jpg?20120424154419", |
| 91 | + @"http://static2.dmcdn.net/static/video/096/991/44199690:jpeg_preview_small.jpg?20120423162001", |
| 92 | + @"http://static2.dmcdn.net/static/video/661/450/44054166:jpeg_preview_small.jpg?20120507180921", |
| 93 | + @"http://static2.dmcdn.net/static/video/419/322/44223914:jpeg_preview_small.jpg?20120424112858", |
| 94 | + @"http://static2.dmcdn.net/static/video/673/391/44193376:jpeg_preview_small.jpg?20120507181450", |
| 95 | + @"http://static2.dmcdn.net/static/video/907/781/44187709:jpeg_preview_small.jpg?20120423103507", |
| 96 | + @"http://static2.dmcdn.net/static/video/446/571/44175644:jpeg_preview_small.jpg?20120423033122", |
| 97 | + @"http://static2.dmcdn.net/static/video/146/671/44176641:jpeg_preview_small.jpg?20120428235503", |
| 98 | + @"http://static2.dmcdn.net/static/video/463/571/44175364:jpeg_preview_small.jpg?20120428235503", |
| 99 | + @"http://static2.dmcdn.net/static/video/442/471/44174244:jpeg_preview_small.jpg?20120428235502", |
| 100 | + @"http://static2.dmcdn.net/static/video/523/471/44174325:jpeg_preview_small.jpg?20120422205107", |
| 101 | + @"http://static2.dmcdn.net/static/video/977/159/43951779:jpeg_preview_small.jpg?20120420182100", |
| 102 | + @"http://static2.dmcdn.net/static/video/875/880/40088578:jpeg_preview_small.jpg?20120501131026", |
| 103 | + @"http://static2.dmcdn.net/static/video/434/992/38299434:jpeg_preview_small.jpg?20120503193356", |
| 104 | + @"http://static2.dmcdn.net/static/video/448/798/42897844:jpeg_preview_small.jpg?20120418155203", |
| 105 | + @"http://static2.dmcdn.net/static/video/374/690/44096473:jpeg_preview_small.jpg?20120507181124", |
| 106 | + @"http://static2.dmcdn.net/static/video/284/313/43313482:jpeg_preview_small.jpg?20120420184511", |
| 107 | + @"http://static2.dmcdn.net/static/video/682/060/44060286:jpeg_preview_small.jpg?20120421122436", |
| 108 | + @"http://static2.dmcdn.net/static/video/701/750/44057107:jpeg_preview_small.jpg?20120420112918", |
| 109 | + @"http://static2.dmcdn.net/static/video/790/850/44058097:jpeg_preview_small.jpg?20120424114522", |
| 110 | + @"http://static2.dmcdn.net/static/video/153/617/43716351:jpeg_preview_small.jpg?20120419190650", |
| 111 | + @"http://static2.dmcdn.net/static/video/394/633/37336493:jpeg_preview_small.jpg?20111109151109", |
| 112 | + @"http://static2.dmcdn.net/static/video/893/330/44033398:jpeg_preview_small.jpg?20120419123322", |
| 113 | + @"http://static2.dmcdn.net/static/video/395/046/42640593:jpeg_preview_small.jpg?20120418103546", |
| 114 | + @"http://static2.dmcdn.net/static/video/913/040/44040319:jpeg_preview_small.jpg?20120419164908", |
| 115 | + @"http://static2.dmcdn.net/static/video/090/020/44020090:jpeg_preview_small.jpg?20120418185934", |
| 116 | + @"http://static2.dmcdn.net/static/video/349/299/43992943:jpeg_preview_small.jpg?20120418112749", |
| 117 | + @"http://static2.dmcdn.net/static/video/530/189/43981035:jpeg_preview_small.jpg?20120419013834", |
| 118 | + @"http://static2.dmcdn.net/static/video/763/469/43964367:jpeg_preview_small.jpg?20120425111931", |
| 119 | + @"http://static2.dmcdn.net/static/video/961/455/43554169:jpeg_preview_small.jpg?20120418110127", |
| 120 | + @"http://static2.dmcdn.net/static/video/666/889/43988666:jpeg_preview_small.jpg?20120507180735", |
| 121 | + @"http://static2.dmcdn.net/static/video/160/459/43954061:jpeg_preview_small.jpg?20120501202847", |
| 122 | + @"http://static2.dmcdn.net/static/video/352/069/43960253:jpeg_preview_small.jpg?20120503175747", |
| 123 | + @"http://static2.dmcdn.net/static/video/096/502/43205690:jpeg_preview_small.jpg?20120417142655", |
| 124 | + @"http://static2.dmcdn.net/static/video/257/119/43911752:jpeg_preview_small.jpg?20120416101238", |
| 125 | + @"http://static2.dmcdn.net/static/video/874/098/43890478:jpeg_preview_small.jpg?20120415193608", |
| 126 | + @"http://static2.dmcdn.net/static/video/406/148/43841604:jpeg_preview_small.jpg?20120416123145", |
| 127 | + @"http://static2.dmcdn.net/static/video/463/885/43588364:jpeg_preview_small.jpg?20120409130206", |
| 128 | + @"http://static2.dmcdn.net/static/video/176/845/38548671:jpeg_preview_small.jpg?20120414200742", |
| 129 | + nil]; |
| 130 | + } |
| 131 | + return self; |
| 132 | +} |
| 133 | + |
| 134 | +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation |
| 135 | +{ |
| 136 | + return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); |
| 137 | +} |
| 138 | + |
| 139 | +#pragma mark - Table View |
| 140 | + |
| 141 | +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView |
| 142 | +{ |
| 143 | + return 1; |
| 144 | +} |
| 145 | + |
| 146 | +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section |
| 147 | +{ |
| 148 | + return _objects.count; |
| 149 | +} |
| 150 | + |
| 151 | +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath |
| 152 | +{ |
| 153 | + static NSString *CellIdentifier = @"Cell"; |
| 154 | + |
| 155 | + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
| 156 | + if (cell == nil) |
| 157 | + { |
| 158 | + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; |
| 159 | + } |
| 160 | + |
| 161 | + cell.textLabel.text = [NSString stringWithFormat:@"Image #%d", indexPath.row]; |
| 162 | + [cell.imageView setImageWithURL:[NSURL URLWithString:[_objects objectAtIndex:indexPath.row]] |
| 163 | + placeholderImage:[UIImage imageNamed:@"placeholder"]]; |
| 164 | + return cell; |
| 165 | +} |
| 166 | + |
| 167 | +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath |
| 168 | +{ |
| 169 | + if (!self.detailViewController) |
| 170 | + { |
| 171 | + self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; |
| 172 | + } |
| 173 | + NSString *largeImageURL = [[_objects objectAtIndex:indexPath.row] stringByReplacingOccurrencesOfString:@"small" withString:@"source"]; |
| 174 | + self.detailViewController.imageURL = [NSURL URLWithString:largeImageURL]; |
| 175 | + [self.navigationController pushViewController:self.detailViewController animated:YES]; |
| 176 | +} |
| 177 | + |
| 178 | +@end |
0 commit comments