// // MessaggioInformativoTableViewController.m // Earthquake Network // // Created by Luca Beretta on 13/01/2019. // Copyright © 2019 Luca Beretta. All rights reserved. // #import "MessaggioInformativoTableViewController.h" #import "EQNUtility.h" #import "EQNNotificheTsunami.h" @interface MessaggioInformativoTableViewController () @end @implementation MessaggioInformativoTableViewController - (void)viewDidLoad { [super viewDidLoad]; if (![EQNNotificheTsunami center].listaMessaggi) { [EQNNotificheTsunami center].listaMessaggi = [[EQNUtility arrayMessaggiTsunami] 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 arrayMessaggiTsunami].count;; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellSection"]; UILabel *titolo = (UILabel *)[cell viewWithTag:1]; titolo.text = NSLocalizedString(@"Tipo messaggio", @"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 arrayMessaggiTsunami][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].listaMessaggi 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].listaMessaggi mutableCopy]; NSString *selezioneEnete = [EQNUtility arrayMessaggiTsunami][indexPath.row]; if ([array containsObject:selezioneEnete]) [array removeObject:selezioneEnete]; else [array addObject:selezioneEnete]; [EQNNotificheTsunami center].listaMessaggi = [NSArray arrayWithArray:array]; [[EQNNotificheTsunami center] saveUserInfo]; [self.tableView reloadData]; } @end