2017-06-13 8 views
0

私は、Twitterのクローンを作成するためのビデオチュートリアルに従います。このチュートリアルは速い2で書かれています。私はスイフト3を申請しようとしました。でも、3回目のビデオでは問題があります。私はつぶやきを保存することができますが、私はそれがどのようにtableviewで表示することができないのか分かりません。テーブルビューでデータをリロードするFirebase with Swift 3

let tweet = tweets[(self.tweets.count-1) - indexPath.row]!.value["text"] as! String 

Videoシリーズ::ここtwitter clone with firebase

プロジェクト:ここGithub Link

私の問題:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let cell: HomeViewTableViewCell = tableView.dequeueReusableCellWithIdentifier("HomeViewTableViewCell", forIndexPath: indexPath) as! HomeViewTableViewCell 


    let tweet = tweets[(self.tweets.count-1) - indexPath.row]!.value["text"] as! String 

    cell.configure(nil,name:self.loggedInUserData!.value["name"] as! String,handle:self.loggedInUserData!.value["handle"] as! String,tweet:tweet) 


    return cell 
} 

エラー: "メンバーのカウントにあいまいな参照" 彼は、このラインを使用しています。

+0

エラーを表示する必要があります –

答えて

0

最後に私は私の問題を解決しました。 Swift 3.1のように更新:

self.homeTableView.insertRows(at: [IndexPath(row:self.tweets.count-1,section:0)], with: UITableViewRowAnimation.automatic) 

私は上記のコードをviewDidLoadで使用しました。 そして私はつぶやき[indexPath.row]を使用します。

0

ツイートを表示するには、オブザーバーをFirebase Real-Time Databaseに追加する必要があります。次のセクションで、

self.databaseRef.child("tweets/\(self.loggedInUser!.uid)").observeEventType(.ChildAdded, withBlock: { (snapshot:FIRDataSnapshot) in 
     self.tweets.append(snapshot)  
     self.homeTableView.insertRowsAtIndexPaths([NSIndexPath(forRow:0,inSection:0)], withRowAnimation: UITableViewRowAnimation.Automatic) 

     self.aivLoading.stopAnimating() 

    }){(error) in 

     print(error.localizedDescription) 
    } 

を見れば

self.databaseRef.child("user_profiles").child(self.loggedInUser!.uid).observeSingleEventOfType(.Value) { (snapshot:FIRDataSnapshot) in 

     //store the logged in users details into the variable 
     self.loggedInUserData = snapshot 
     print(self.loggedInUserData) 

     //get all the tweets that are made by the user 

     self.databaseRef.child("tweets/\(self.loggedInUser!.uid)").observeEventType(.ChildAdded, withBlock: { (snapshot:FIRDataSnapshot) in 


      self.tweets.append(snapshot) 


      self.homeTableView.insertRowsAtIndexPaths([NSIndexPath(forRow:0,inSection:0)], withRowAnimation: UITableViewRowAnimation.Automatic) 

      self.aivLoading.stopAnimating() 

     }){(error) in 

      print(error.localizedDescription) 
     } 

    } 

彼は、データベースへのオブザーバーを追加して、いつでも参照に追加取得ノードが存在する、上記のコードがトリガされます。これを正しく行ったかどうか確認してください。

これを正しく実行した場合は、オブザーバーを正確なノードに追加してください。ここでは、オブザーバはtweet - >userIDというノードに接続されています。データベースの構成が異なる場合、参照は異なります。

あなたが学んでいるとき、私はあなたにSwift 3の構文に変換を残します。

+0

ありがとう、しかし私の問題はここにありません。私は質問を更新しました。 – Mayday

関連する問題