Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // BNRItemsViewController.m
- // Homepwner
- //
- //
- #import "BNRItemsViewController.h"
- #import "BNRItemStore.h"
- #import "BNRItem.h"
- @implementation BNRItemsViewController
- // Designated initializer
- - (instancetype) init {
- self = [super initWithStyle:UITableViewStyleGrouped];
- if (self) {
- for (int i = 0; i < 5; i++) {
- [[BNRItemStore sharedStore] createItem];
- }
- }
- return self;
- }
- - (instancetype) initWithStyle:(UITableViewStyle)style {
- return [self init];
- }
- - (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- if (section == 0) {
- return 25;
- }
- else
- return 1;
- }
- - (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 1;
- }
- - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
- return 2;
- }
- - (BOOL) tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.row == 0) {
- return NO;
- }
- return YES;
- }
- - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [[[BNRItemStore sharedStore] allItems] count];
- }
- - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
- NSArray *itemsOverFifty = [[BNRItemStore sharedStore] allItems];
- BNRItem *item = itemsOverFifty[indexPath.row];
- if (indexPath.section == 1 && indexPath.row == 4) {
- cell.textLabel.text = @"No More Items!";
- return cell;
- }
- // Section ==0, > $50
- if (indexPath.section == 0 && item.valueInDollars > 50) {
- cell.textLabel.text = [item description];
- return cell;
- }
- // Section ==1, <= $50
- if (indexPath.section == 1 && item.valueInDollars <= 50) {
- if (indexPath.row == 4) {
- cell.textLabel.text = @"No More Items!";
- }
- else {
- cell.textLabel.text = [item description];
- }
- return cell;
- }
- return cell;
- }
- - (void) viewDidLoad {
- [super viewDidLoad];
- [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement