【发布时间】:2016-10-29 08:45:18
【问题描述】:
我从 Firebase 收到重复的内容,但我似乎无法弄清楚我做错了什么。在火力基地我有 6 个职位。表格视图正在填充 6 个单元格,但所有 6 个单元格都具有相同的数据,并且其他 5 个帖子不存在。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
RankingsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RankingsCell"];
self.ref = [[FIRDatabase database] reference];
posts = [ref child:@"posts"];
[posts observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot)
{
for (snapshot in snapshot.children)
{
NSString *username = snapshot.value[@"Name"];
NSString *date = snapshot.value[@"Date"];
NSString *combatPower = snapshot.value[@"Combat Power"];
NSString *pokemon = snapshot.value[@"Pokemon"];
NSString *pokemonURL = snapshot.value[@"Pokemon Image"];
NSString *picURL = snapshot.value[@"Profile Picture"];
int CP = [combatPower intValue];
cell.usernameOutlet.text = username;
cell.dateOutlet.text = date;
cell.combatPowerLabel.text = [NSString stringWithFormat:@"COMBAT POWER: %d", CP];
cell.pokemonLabel.text = pokemon;
[cell downloadUserImage:picURL];
[cell downloadPokemonImage:pokemonURL];
}
}
withCancelBlock:^(NSError * _Nonnull error)
{
NSLog(@"%@", error.localizedDescription);
}];
return cell;
}
【问题讨论】:
-
不要像这样直接使用firebase数据将其存储在一个数组中并访问它
-
我不确定如何将所有这些值存储到 NSArray 中,然后将它们拉取...
-
当你得到响应然后创建一个数组给你的快照和表 cellrowatindex 的值只是访问你的 nsarray
-
对不起,你能给我举个小例子来说明你的意思吗?
-
那是 Swift 代码吗?
标签: ios objective-c uitableview firebase firebase-realtime-database