Created
October 12, 2013 20:13
-
-
Save Cellane/6954376 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ItemsViewController.m | |
// Homepwner | |
// | |
// Created by Milan Vít on 12.10.13. | |
// Copyright (c) 2013 Milan Vít. All rights reserved. | |
// | |
#import "ItemsViewController.h" | |
#import "BNRItemStore.h" | |
#import "BNRItem.h" | |
@implementation ItemsViewController | |
- (id)init | |
{ | |
self = [super initWithStyle:UITableViewStylePlain]; | |
if (self) { | |
for (int i = 0; i < 5; i++) { | |
[[BNRItemStore sharedStore] createItem]; | |
} | |
} | |
// iOS 7 hack | |
[[self tableView] setContentInset:UIEdgeInsetsMake([[[self navigationController] navigationBar] frame].size.height + [[UIApplication sharedApplication] statusBarFrame].size.height, 0, 0, 0)]; | |
return self; | |
} | |
- (id)initWithStyle:(UITableViewStyle)style | |
{ | |
return [self init]; | |
} | |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView | |
{ | |
return 2; | |
} | |
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
return 42; | |
} | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section | |
{ | |
int counter = 0; | |
for (BNRItem *item in [[BNRItemStore sharedStore] allItems]) { | |
if ((section == 0 && [item valueInDollars] > 50) || | |
(section == 1 && [item valueInDollars] <= 50)) { | |
counter++; | |
} | |
} | |
if (section == 1) { | |
counter++; | |
} | |
return counter; | |
} | |
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section | |
{ | |
return (section == 0) ? @"Items over $50" : @"Items at or below $50"; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"]; | |
int section = [indexPath section]; | |
if (!cell) { | |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault | |
reuseIdentifier:@"UITableViewCell"]; | |
} | |
if (section == 0) { | |
[[cell textLabel] setText:[[[[BNRItemStore sharedStore] expensiveItems] objectAtIndex:[indexPath row]] description]]; | |
} | |
else | |
{ | |
if ([indexPath row] < [[[BNRItemStore sharedStore] cheapItems] count]) { | |
[[cell textLabel] setText:[[[[BNRItemStore sharedStore] cheapItems] objectAtIndex:[indexPath row]] description]]; | |
} | |
else | |
{ | |
[[cell textLabel] setText:@"No more items!"]; | |
} | |
} | |
return cell; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment