summaryrefslogtreecommitdiff
path: root/cakeside-ios
diff options
context:
space:
mode:
Diffstat (limited to 'cakeside-ios')
-rw-r--r--cakeside-ios/assets/placeholder.pngbin0 -> 71622 bytes
-rw-r--r--cakeside-ios/controllers/CreationsTableViewController.m61
-rw-r--r--cakeside-ios/models/Cake.h1
-rw-r--r--cakeside-ios/models/Cake.m1
4 files changed, 43 insertions, 20 deletions
diff --git a/cakeside-ios/assets/placeholder.png b/cakeside-ios/assets/placeholder.png
new file mode 100644
index 0000000..14c1090
--- /dev/null
+++ b/cakeside-ios/assets/placeholder.png
Binary files differ
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;
}