// // DialogsViewController.m // Juick // // Created by Vitaly Takmazov on 04/03/2018. // Copyright © 2018 com.juick. All rights reserved. // #import "DialogsViewController.h" #import "ColorScheme.h" #import "ConversationCell.h" #import "APIClient.h" @interface DialogsViewController () @end @implementation DialogsViewController - (void)viewDidLoad { [super viewDidLoad]; [self.view setBackgroundColor:[ColorScheme mainBackground]]; [self.tableView registerNib:[UINib nibWithNibName:@"ConversationCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"notificationCell"]; self.chats = [NSMutableArray array]; [[APIClient sharedClient] fetchChats:^(NSArray *groups, NSError *err) { if (err == nil) { [self.chats addObjectsFromArray:groups]; NSMutableArray *indexPaths = [NSMutableArray new]; for (NSUInteger index = 0; index < [groups count]; index++) { [indexPaths addObject:[NSIndexPath indexPathForRow:index inSection: 0]]; } [self.tableView beginUpdates]; [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES]; [self.tableView endUpdates]; } }]; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.chats.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ConversationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"notificationCell" forIndexPath:indexPath]; [cell configureWithChat:[self.chats objectAtIndex:indexPath.row]]; return cell; } @end