FirebaseUI:使用FUIIndexTableViewDataSource时如何在segue期间访问indexPath上的对象?

时间:2016-12-14 17:16:36

标签: swift uitableview firebase-realtime-database segue firebaseui

我正在使用FUIIndexTableViewDataSource,如https://github.com/firebase/FirebaseUI-iOS/tree/master/FirebaseDatabaseUI所述。

我想在点击某个项目时显示详细视图控制器,但在准备segue时我不知道如何获取引用,键或数据。

我的代码:

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "showDetail" {
            if let indexPath = self.tableView.indexPathForSelectedRow {
                // HELP: How do I access the firebase reference, index, and data from here?
            }
        }
    } 

在setupDatabase()函数中,我设置了数据源。

self.dataSource = self.tableView.bind(
    toIndexedQuery: chatKeysRef,
    data: chatDataRef,
    delegate: self,
    populateCell:  {
        (tableView, indexPath, dataSnapshot) in

        let cell = tableView.dequeueReusableCell(withIdentifier: "Chat", for: indexPath);

        if (dataSnapshot == nil) {
            cell.textLabel?.text = "";
            cell.detailTextLabel?.text = "";
            return cell;
        }

        cell.textLabel?.text = "hello world"

        if (dataSnapshot!.hasChild("most_recent_message")) {
            cell.detailTextLabel?.text = dataSnapshot?.childSnapshot(forPath: "most_recent_message").value as? String;
        }

        return cell;
});

FUIIndexTableViewDataSource似乎没有任何可以帮助我的公共属性或方法:https://github.com/firebase/FirebaseUI-iOS/blob/master/FirebaseDatabaseUI/FUIIndexTableViewDataSource.h

Readme.md引用了FUIDataSource,但似乎没有出现在FUIIndexTableViewDataSource中。

1 个答案:

答案 0 :(得分:0)

所选行的数据可以像这样读取

{{1}}