【发布时间】:2017-01-26 07:52:30
【问题描述】:
我正在尝试检索数据并在 UITable 视图中显示它们。首先,我想从数据库中检索协议。目前只有一个协议记录,但未来会有很多记录。我试过下面的代码
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
//self.clearsSelectionOnViewWillAppear = NO;
[[_firebaseDatabaseRef child:@"krib-60229"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *_Nonnull snapshot){
self.allSnapshot = [NSMutableArray array];
NSLog(@"%@",self.allSnapshot);
NSLog(@"%s","TestTestTest");
for(snapshot in snapshot.children){
[self.allSnapshot addObject:snapshot];
}
[self.tableView reloadData];
}];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.allSnapshot count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
FIRDataSnapshot *snapShot = [self.allSnapshot objectAtIndex:indexPath.row];
NSString *testText = snapShot.value[@"landlordDisplayName"];
cell.textLabel.text = testText;
// Configure the cell...
return cell;
}
我也没有得到任何检索或任何错误。我尝试放置 NSLog,但它们也没有打印。
【问题讨论】:
标签: ios objective-c uitableview firebase firebase-realtime-database