【发布时间】:2018-08-06 01:14:34
【问题描述】:
我正在使用 Firebase 来管理我的应用数据。
到目前为止,Firebase 似乎非常适合管理数据,但是当我需要从数据库中读取数据时遇到了问题..
要从我的 Firebase 数据库中读取数据,我执行此功能
[[[[FIRDatabase database] reference] child:@"Region"] observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
[_regionList addObject:snapshot.value[@"name"]];
[self.collectionView reloadData];
}];
数据以正确的方式收集,但问题是它似乎有点慢......
为了让你更好地理解...
我必须在UICollectionView 中查看我的数据。问题是在查看UICollectionView 和收集的数据之间似乎有一点延迟……你可以从我在下面发布的视频..
你能告诉我我的错误在哪里吗?我似乎做的一切都正确,但我不明白读取数据的这种延迟
这是我的代码
- (void)viewDidLoad {
[super viewDidLoad];
_regionList = [[NSMutableArray alloc] init];
_reference = [[DatabaseReference alloc] init];
[self fetchRegion];
}
-(void)fetchRegion {
[[[[FIRDatabase database] reference] child:@"Region"] observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
[_regionList addObject:snapshot.value[@"name"]];
[self.collectionView reloadData];
}];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.regionList.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
ChooseRegionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
cell.regionName.text = self.regionList[indexPath.item];
return cell;
}
【问题讨论】:
标签: ios objective-c firebase firebase-realtime-database uicollectionview