Advertisement
Guest User

Filter.m

a guest
Mar 24th, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  FilterListViewController.m
  3. //  TourMyTown
  4. //
  5. //  Created by Michael Katz on 10/10/13.
  6. //  Copyright (c) 2013 mikekatz. All rights reserved.
  7. //
  8.  
  9. #import "FilterListViewController.h"
  10.  
  11. #import "Categories.h"
  12.  
  13. @interface FilterListViewController ()
  14. @property (nonatomic, retain) NSMutableArray* selections;
  15. @end
  16.  
  17. @implementation FilterListViewController
  18.  
  19. - (id)initWithStyle:(UITableViewStyle)style
  20. {
  21.     self = [super initWithStyle:style];
  22.     if (self) {
  23.         // Custom initialization
  24.     }
  25.     return self;
  26. }
  27.  
  28. - (instancetype) initWithSelectedCategories:(NSArray*)selections deleagte:(id<CategoryDelegate>)delegate
  29. {
  30.     self = [super init];
  31.     if (self) {
  32.         self.delegate = delegate;
  33.         self.selections = [NSMutableArray arrayWithArray:selections];
  34.     }
  35.     return self;
  36. }
  37.  
  38.  
  39. - (void)viewDidLoad
  40. {
  41.     [super viewDidLoad];
  42.     id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
  43.     [tracker set:kGAIScreenName value:@"Filtros"];
  44.     [tracker send:[[GAIDictionaryBuilder createAppView] build]];
  45.  
  46.     [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
  47.     self.title = @"Escolha as Categorias";
  48. }
  49.  
  50. - (void)didReceiveMemoryWarning
  51. {
  52.     [super didReceiveMemoryWarning];
  53.     // Dispose of any resources that can be recreated.
  54. }
  55.  
  56. - (void)viewWillDisappear:(BOOL)animated
  57. {
  58.     [self.delegate selectedCategories:self.selections];
  59. }
  60.  
  61. #pragma mark - Table view data source
  62.  
  63. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  64. {
  65.     return 1;
  66. }
  67.  
  68. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  69. {
  70.     return [Categories allCategories].count + 1;
  71. }
  72.  
  73. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  74. {
  75.     static NSString *CellIdentifier = @"Cell";
  76.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  77.     if(indexPath.row == 0) {
  78.         cell.textLabel.textColor = [UIColor blueColor];
  79.         cell.textLabel.text = @"Salvar";
  80.     }
  81.     else {
  82.     NSString* category = [Categories allCategories][(indexPath.row - 1)];
  83.     cell.textLabel.text = category;
  84.     cell.accessoryType = [self.selections containsObject:category] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
  85.     cell.selectionStyle = UITableViewCellSelectionStyleNone;
  86.     }
  87.     return cell;
  88. }
  89.  
  90. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  91. {
  92.     if(indexPath.row == 0) {
  93.         [self.navigationController popViewControllerAnimated:YES];
  94.     }
  95.     else {
  96.  
  97.     NSString* category = [Categories allCategories][(indexPath.row-1)];
  98.     BOOL on = [self.selections containsObject:category];
  99.     if (on) {
  100.         [self.selections removeObject:category];
  101.     } else {
  102.         [self.selections addObject:category];
  103.     }
  104.     [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  105.     }
  106. }
  107. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement