diff options
| author | mo khan <mo@mokhan.ca> | 2013-07-14 18:25:55 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-07-14 18:25:55 -0600 |
| commit | 710bdf83209e2f83f6fec3312bc4449bf13ba60d (patch) | |
| tree | 22ee0235d4bb2bd0683cb5ceb39f1b55fa77edc3 | |
| parent | 6100ccb8f66b9e1880fb1ac8b3028c44156e20f1 (diff) | |
display image of each creation in the table view
| -rw-r--r-- | cakeside-ios.xcodeproj/project.pbxproj | 12 | ||||
| -rw-r--r-- | cakeside-ios/assets/placeholder.png | bin | 0 -> 71622 bytes | |||
| -rw-r--r-- | cakeside-ios/controllers/CreationsTableViewController.m | 61 | ||||
| -rw-r--r-- | cakeside-ios/models/Cake.h | 1 | ||||
| -rw-r--r-- | cakeside-ios/models/Cake.m | 1 |
5 files changed, 55 insertions, 20 deletions
diff --git a/cakeside-ios.xcodeproj/project.pbxproj b/cakeside-ios.xcodeproj/project.pbxproj index 0007195..d8cab60 100644 --- a/cakeside-ios.xcodeproj/project.pbxproj +++ b/cakeside-ios.xcodeproj/project.pbxproj @@ -30,6 +30,7 @@ CDE67AC417935C1C00B4742C /* CreationsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CDE67AC217935C1C00B4742C /* CreationsTableViewController.m */; }; CDE67AC517935C1C00B4742C /* CreationsTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = CDE67AC317935C1C00B4742C /* CreationsTableViewController.xib */; }; CDE67ACB179364A600B4742C /* Cake.m in Sources */ = {isa = PBXBuildFile; fileRef = CDE67ACA179364A600B4742C /* Cake.m */; }; + CDE67AD0179375DA00B4742C /* placeholder.png in Resources */ = {isa = PBXBuildFile; fileRef = CDE67ACF179375DA00B4742C /* placeholder.png */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -76,6 +77,7 @@ CDE67AC317935C1C00B4742C /* CreationsTableViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = CreationsTableViewController.xib; path = ../controllers/CreationsTableViewController.xib; sourceTree = "<group>"; }; CDE67AC9179364A600B4742C /* Cake.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cake.h; sourceTree = "<group>"; }; CDE67ACA179364A600B4742C /* Cake.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Cake.m; sourceTree = "<group>"; }; + CDE67ACF179375DA00B4742C /* placeholder.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = placeholder.png; sourceTree = "<group>"; }; CE65D4B28521438085302B5E /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -141,6 +143,7 @@ CDCB34611793405E00A25F1E /* cakeside-ios */ = { isa = PBXGroup; children = ( + CDE67ACE179375DA00B4742C /* assets */, CDE67AB317934E4200B4742C /* utility */, CDE67AAD1793471B00B4742C /* controllers */, CDE67AAC1793471200B4742C /* views */, @@ -225,6 +228,14 @@ path = utility; sourceTree = "<group>"; }; + CDE67ACE179375DA00B4742C /* assets */ = { + isa = PBXGroup; + children = ( + CDE67ACF179375DA00B4742C /* placeholder.png */, + ); + path = assets; + sourceTree = "<group>"; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -304,6 +315,7 @@ CDCB34721793405E00A25F1E /* Default-568h@2x.png in Resources */, CDCB34781793405E00A25F1E /* LoginViewController.xib in Resources */, CDE67AC517935C1C00B4742C /* CreationsTableViewController.xib in Resources */, + CDE67AD0179375DA00B4742C /* placeholder.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/cakeside-ios/assets/placeholder.png b/cakeside-ios/assets/placeholder.png Binary files differnew file mode 100644 index 0000000..14c1090 --- /dev/null +++ b/cakeside-ios/assets/placeholder.png diff --git a/cakeside-ios/controllers/CreationsTableViewController.m b/cakeside-ios/controllers/CreationsTableViewController.m index e5d6f8d..5b9e657 100644 --- a/cakeside-ios/controllers/CreationsTableViewController.m +++ b/cakeside-ios/controllers/CreationsTableViewController.m @@ -33,6 +33,11 @@ // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(updatedDataNotification) + name:NOTIFICATION_UPDATED_STATS_DATA + object:nil]; // start loading data... [self updateData]; } @@ -43,6 +48,11 @@ // Dispose of any resources that can be recreated. } +- (void)updatedDataNotification +{ + [self.tableView reloadData]; +} + - (void)updateData { self.data = nil; @@ -56,7 +66,6 @@ [httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]]; [httpClient setDefaultHeader:@"Accept" value:@"application/json"]; [httpClient setDefaultHeader:@"Authorization" value:[NSString stringWithFormat:@"Token token=%@", token]]; -// Authorization: Token token= [httpClient setParameterEncoding:AFJSONParameterEncoding]; NSMutableURLRequest *request; @@ -82,7 +91,7 @@ [self.data addObject:cake]; } -// [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_UPDATED_STATS_DATA object:nil]; + [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_UPDATED_STATS_DATA object:nil]; } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { @@ -106,39 +115,51 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { -#warning Potentially incomplete method implementation. - // Return the number of sections. - return 0; + return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { -#warning Incomplete method implementation. - // Return the number of rows in the section. - return 0; + if (!self.data) + { + return 0; // Loading + } + else if (self.data.count == 0) + { + return 1; // no data + } + else + { + return self.data.count; + } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - static NSString *CellIdentifier = @"Cell"; - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; - if (cell == nil) { - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; - } - - // Configure the cell... - - return cell; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReadingCell"]; + if (cell == nil) + { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ReadingCell"]; + } + + + Cake *cake = [self.data objectAtIndex:indexPath.row]; + [cell.imageView setImageWithURL:[NSURL URLWithString:cake.photo] + placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; + + cell.textLabel.text = cake.name; + return cell; + } -/* + // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. - return YES; + return NO; } -*/ + /* // Override to support editing the table view. diff --git a/cakeside-ios/models/Cake.h b/cakeside-ios/models/Cake.h index da71cc9..3365f64 100644 --- a/cakeside-ios/models/Cake.h +++ b/cakeside-ios/models/Cake.h @@ -12,4 +12,5 @@ + (Cake *)initFromJSON:(NSDictionary *)jsonData; @property (nonatomic) NSInteger id; @property (nonatomic) NSString *name; +@property (nonatomic) NSString *photo; @end diff --git a/cakeside-ios/models/Cake.m b/cakeside-ios/models/Cake.m index f484881..5b3c967 100644 --- a/cakeside-ios/models/Cake.m +++ b/cakeside-ios/models/Cake.m @@ -15,6 +15,7 @@ Cake *result = [[Cake alloc] init]; result.id = [[jsonData objectForKey:@"id"] integerValue]; result.name = [jsonData objectForKey:@"name"]; + result.photo = [jsonData objectForKey:@"photo"]; return result; } |
