2016-09-30 91 views
0

我想用自定義的UITableViewCells使用FirebaseUI填充UITableView。除了FirebaseTableViewDataSource.populateCell()方法提供的TableViewCell沒有「連接」到視圖中的插座外,一切似乎都奏效。這裏有一個例子:iOS的FirebaseUI與自定義UITableViewCell

這是自定義的UITableViewCell類。正在加載的視圖控制器的故事板中的UITableView具有此自定義單元類。

class JobTableViewCell : UITableViewCell { 
    @IBOutlet weak var labelJobName: UILabel! 
} 

下面是viewDidLoad中()的視圖控制器是建立在表的代碼:

dataSource = FirebaseTableViewDataSource(ref : ref, cellClass : JobTableViewCell.self, cellReuseIdentifier: "JobTableViewCell", view: self.tableView); 


dataSource.populateCell{(cell : UITableViewCell, obj : NSObject) -> Void in 
    let snapshot = obj as! FIRDataSnapshot; 
    let job = Job(snapshot); 
    let jobCell = cell as! JobTableViewCell 
    ////////////////////////////////////////////////////////// 
    // jobCell and its outlets are nil so this next statement 
    // causes exception. 
    jobCell.labelJobName.text = job.name; 

} 
self.tableView.dataSource = self.dataSource; 

所以現在的問題是如何獲得FirebaseUI與網點提供的自定義單元格有線嗎?我無法弄清楚如何去做。

回答

4

我的解決方案是停止使用iOS版FirebaseUI。

1

您需要使用self.tableView.bind

例如,

var dataSource: FUITableViewDataSource! 

self.dataSource = self.tableView.bind(to: ref) { tableView, indexPath, snapshot in 
    // Dequeue cell 
    let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) 
    /* populate cell */ 
    return cell 
} 

Firebase UI database for iOS更多信息