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 /cakeside-ios/controllers/CreationsTableViewController.m | |
| parent | 6100ccb8f66b9e1880fb1ac8b3028c44156e20f1 (diff) | |
display image of each creation in the table view
Diffstat (limited to 'cakeside-ios/controllers/CreationsTableViewController.m')
| -rw-r--r-- | cakeside-ios/controllers/CreationsTableViewController.m | 61 |
1 files changed, 41 insertions, 20 deletions
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. |
