【发布时间】:2017-05-07 17:29:11
【问题描述】:
我正在实现一个简单的聊天视图控制器。在从 Firebase 添加孩子时,它会冻结 UI,直到它给出最后一个孩子。奇怪的行为。 这是代码sn-p-
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
chatArray=[NSMutableArray new];
ref=(FIRDatabaseReference *)[[FIRDatabase database] reference];
refHandleForGettingChatInfo=[[ref child:@"Chat"] observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot)
{
NSLog(@"New chat");
NSDictionary<NSString *, NSString *> *message = snapshot.value;
[chatArray addObject:message];
dispatch_async(dispatch_get_main_queue(), ^{
[tblChat reloadData];
});
}];
}
#pragma mark - Table View delegates and DataSources
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return chatArray.count;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString * CellIdentifier =@"ChatTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
NSDictionary *message=[chatArray objectAtIndex:indexPath.row];
cell.textLabel.text=[message valueForKey:@"userName"];
cell.detailTextLabel.text=[message valueForKey:@"userMessage"];
return cell;
}
Xcode 版本:8.3.2
部署目标:10.2
如果有人遇到过同样的问题,请告诉我最适合这种情况的解决方案。谢谢
【问题讨论】:
标签: ios objective-c uitableview firebase firebase-realtime-database