0

我在 Firebase 中创建了一个位置列表,我试图在我的 iOS 应用程序中读取它,然后将其作为 PickerView 进行查看。

火力基地位置

下面是我如何读取数据。

 ref.child("locations").observeSingleEventOfType(.Value, withBlock: { snapshot in
            self.listOfLocations = snapshot.value as! [String]
        })

PickerView 的代码

func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return listOfLocations.count;
    }

    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return listOfLocations[row]
    }

    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int){
        selectedLocation = listOfLocations[row]
    }

但是,我收到一个错误,程序在快照行停止执行。

在我看来,问题是读取的数据是 AnyObject 类型,在 PickerView 中我需要 String。将 [AnyObject] 类型转换为 [String] 不适用于我。

我将不胜感激帮助解决这个问题。

4

0 回答 0