У меня проблемы с заполнением моего табличного представления данными из моей базы данных Firebase.Мой NSMutableArray всегда пуст внутри блока.Как я могу заполнить свой tableView данными, взятыми из моей базы данных?
Только Цель C
До сих пор я реализовал свой код таким образом
@interface UserSearchController ()
@property (nonatomic, strong) NSMutableArray *users;
@end
@implementation UserSearchController
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellID"];
[self retrieveAllUser];
}
-(void)retrieveAllUser {
FIRDatabaseReference *dbRef = FIRDatabase.database.reference;
_users = NSMutableArray.new;
[[[dbRef child:kUserAccFolder] queryOrderedByChild:kUserAccEmail]
observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
[self.users addObject:snapshot.value[kUserAccName]];
[self.tableView reloadData];
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _users.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID" forIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:@"%@",self.users[indexPath.row]];
return cell;
}