// // AreaInteresseTableViewController.m // Earthquake Network // // Created by Luca Beretta on 14/01/2019. // Copyright © 2019 Luca Beretta. All rights reserved. // #import "AreaInteresseTableViewController.h" #import "EQNUtility.h" #import "EQNNotificheTsunami.h" @interface AreaInteresseTableViewController () @end @implementation AreaInteresseTableViewController - (void)viewDidLoad { [super viewDidLoad]; if (![EQNNotificheTsunami center].listaAreeInteresse) { [EQNNotificheTsunami center].listaAreeInteresse = [[EQNUtility arrayAreeInteresseTsunami] copy]; [[EQNNotificheTsunami center] saveUserInfo]; } } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [EQNUtility arrayAreeInteresseTsunami].count;; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellSection"]; UILabel *titolo = (UILabel *)[cell viewWithTag:1]; titolo.text = NSLocalizedString(@"Area di interesse", @"titolo impostazioni notifiche"); return cell; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaSelezioneAbilita" forIndexPath:indexPath]; UILabel *titolo = (UILabel *)[cell viewWithTag:1]; titolo.text = [EQNUtility arrayAreeInteresseTsunami][indexPath.row]; UILabel *stato = (UILabel *)[cell viewWithTag:2]; stato.text = NSLocalizedString(@"Ricevi le notifiche dei sismi rilevati dalle agenzie nazionalie internazionali", @"voce menu"); if ([[EQNNotificheTsunami center].listaAreeInteresse containsObject:titolo.text]){ cell.accessoryType = UITableViewCellAccessoryCheckmark; titolo.textColor = [UIColor blackColor]; stato.textColor = [UIColor blackColor]; }else{ cell.accessoryType = UITableViewCellAccessoryNone; titolo.textColor = [UIColor grayColor]; stato.textColor = [UIColor grayColor]; } return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSMutableArray *array = [[EQNNotificheTsunami center].listaAreeInteresse mutableCopy]; NSString *selezioneEnete = [EQNUtility arrayAreeInteresseTsunami][indexPath.row]; if ([array containsObject:selezioneEnete]) [array removeObject:selezioneEnete]; else [array addObject:selezioneEnete]; [EQNNotificheTsunami center].listaAreeInteresse = [NSArray arrayWithArray:array]; [[EQNNotificheTsunami center] saveUserInfo]; [self.tableView reloadData]; } @end