Advertisement
Jacobhaha

BNRIVC.m

Apr 21st, 2015
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  BNRItemsViewController.m
  3. //  Homepwner
  4. //
  5. //
  6.  
  7. #import "BNRItemsViewController.h"
  8. #import "BNRItemStore.h"
  9. #import "BNRItem.h"
  10.  
  11.  
  12. @implementation BNRItemsViewController
  13.  
  14. // Designated initializer
  15. - (instancetype) init {
  16.  
  17.     self = [super initWithStyle:UITableViewStyleGrouped];
  18.    
  19.     if (self) {
  20.  
  21.         for (int i = 0; i < 5; i++) {
  22.             [[BNRItemStore sharedStore] createItem];
  23.         }
  24.     }
  25.    
  26.     return self;
  27. }
  28.  
  29.  
  30.  
  31. - (instancetype) initWithStyle:(UITableViewStyle)style {
  32.     return [self init];
  33. }
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. - (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  43.     if (section == 0) {
  44.         return 25;
  45.     }
  46.     else
  47.         return 1;
  48. }
  49.  
  50.  
  51.  
  52. - (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  53.     return 1;
  54. }
  55.  
  56.  
  57.  
  58. - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
  59.     return 2;
  60. }
  61.  
  62.  
  63. - (BOOL) tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
  64.     if (indexPath.row == 0) {
  65.         return NO;
  66.     }
  67.    
  68.     return YES;
  69. }
  70.  
  71.  
  72. - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  73.     return [[[BNRItemStore sharedStore] allItems] count];
  74. }
  75.  
  76.  
  77. - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  78.  
  79.  
  80.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
  81.    
  82.     NSArray *itemsOverFifty = [[BNRItemStore sharedStore] allItems];
  83.        
  84.    
  85.     BNRItem *item = itemsOverFifty[indexPath.row];
  86.    
  87.    
  88.    
  89.     if (indexPath.section == 1 && indexPath.row == 4) {
  90.         cell.textLabel.text = @"No More Items!";
  91.        
  92.         return cell;
  93.     }
  94.    
  95.     // Section ==0, > $50
  96.     if (indexPath.section == 0 && item.valueInDollars > 50) {
  97.        
  98.         cell.textLabel.text = [item description];
  99.        
  100.        
  101.         return cell;
  102.     }
  103.    
  104.     // Section ==1, <= $50
  105.     if (indexPath.section == 1 && item.valueInDollars <= 50) {
  106.        
  107.         if (indexPath.row == 4) {
  108.             cell.textLabel.text = @"No More Items!";
  109.         }
  110.         else {
  111.             cell.textLabel.text = [item description];
  112.         }
  113.        
  114.        
  115.         return cell;
  116.     }
  117.    
  118.    
  119.     return cell;
  120. }
  121.  
  122.  
  123.  
  124.  
  125. - (void) viewDidLoad {
  126.     [super viewDidLoad];
  127.  
  128.     [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
  129. }
  130.  
  131.  
  132. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement