Commit 710bdf8

mo khan <mo@mokhan.ca>
2013-07-15 00:25:55
display image of each creation in the table view
1 parent 6100ccb
Changed files (5)
cakeside-ios
cakeside-ios.xcodeproj
cakeside-ios/assets/placeholder.png
Binary file
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.
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
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;
 }
 
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;
 		};