Created
November 18, 2015 13:29
-
-
Save rogerluan/4f98634d97e7529ecf15 to your computer and use it in GitHub Desktop.
Code snippet for blog series.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)reloadData { | |
[self.refreshControl beginRefreshing]; | |
[self.dataManager getData:^(NSArray *json) { | |
//converte os objetos do servidor no nosso modelo de objetos | |
NSMutableArray *items = [NSMutableArray array]; | |
for (NSDictionary *jsonItem in json) { | |
TableData *item = [[TableData alloc] initWithJSON:jsonItem]; | |
item.position = [NSNumber numberWithInteger:[json indexOfObject:jsonItem]+1]; | |
[items addObject:item]; | |
} | |
//salva os objetos e atualiza a table view | |
[self.refreshControl endRefreshing]; | |
self.data = items; | |
[self.tableView reloadData]; | |
} error:^(NSError *error) { | |
[self.refreshControl endRefreshing]; | |
UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Oops...", nil) message:[NSString stringWithFormat:NSLocalizedString(@"Ocorreu Um Erro\n\n%@",nil),error.localizedDescription] preferredStyle:UIAlertControllerStyleAlert]; | |
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]; | |
[alert addAction:cancelAction]; | |
[self presentViewController:alert animated:YES completion:nil]; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment