1
我的應用程序從Firebase數據庫檢索數據,使用我的CustomCell將其放入tableView中,我的目標是當單元格被點擊時,我想要存儲在標籤中的字符串那個竊聽的細胞。訪問來自Firebase in didSelectRowAtIndexPath的CustomCell內容
所以我現在正在嘗試這幾天,所提供的解決方案大多隻適用於靜態單元格,其中內容不動態加載,就像它在這裏。 選項我想:
- 使用數組來存儲內容,然後用
indexPath
讓他們的組合:事實證明,這是困難的,因爲陣列無法與火力地堡同步,導致在indexPath
錯誤的訂單。我還沒有找到一個保持數組同步的庫,但是一般的共識似乎是在使用Firebase時我應該遠離數組。 - 使用代表團或類似建議here關閉:因爲我現在用的是FirebaseUI來填充我的電池,我沒有這兩種方法
cellForRowAtIndexPath
或dequeueReusableCellWithIdentifier
,這也讓一個困難的解決方案。
我到目前爲止有:
func getQuery() -> FIRDatabaseQuery {
let myTopPostsQuery = (ref.child("posts"))
return myTopPostsQuery
}
override func viewDidLoad() {
super.viewDidLoad()
self.ref = FIRDatabase.database().reference()
dataSource = FirebaseTableViewDataSource.init(query: getQuery(),prototypeReuseIdentifier: "Cellident", view: self.tableView)
dataSource?.populateCellWithBlock { (cell: UITableViewCell, obj: NSObject) -> Void in
let customCell = cell as! CustomCellTableViewCell
let snap = obj as! FIRDataSnapshot
let childString = snap.value as! [String : AnyObject]
customCell.textLabel.text = String(childString)} // << This is what I need to access in didSelectRowAtIndexPath
}
tableView.dataSource = dataSource
tableView.delegate = self
}
我的問題是現在是什麼將是一段最實用的方式,如果有一個解決方案,我還沒有考慮?