2017-01-26 10 views
0

私はFirebaseで次のデータベース、私はデータを取得し、uitableのビューでそれらを表示しようとしています enter image description hereはObjective Cの中でuitableの中firebaseデータベースやショーからデータを取得

を持っています。まず、データベースから契約書を取りたいと思います。今のところ合意の記録は1つだけですが、将来は多くの記録が残るでしょう。私は以下のコードを試しました

- (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]; 
    }]; 


} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

#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を置こうとしましたが、印刷していません。私はObjective CでIOSを開発するのが初めてです。どんな助力も感謝します。

答えて

0

次の行を試してください。

FIRDatabaseReference *rootRef= [[FIRDatabase database] referenceFromURL:[NSString stringWithFormat:@"%@/agreements",<database-url>]]; 
    [rootRef observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) 
    { 
     if (snapshot.exists) 
     { 
      NSLog(@“%@”,snapshot.value);    
     } 
    }]; 
関連する問題