ios - PickerView 不显示任何值

标签 ios xcode swift

这是我使用的代码:

// PickerView Functions

func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
    return 1
}

//
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent
    component: Int) -> Int {

            return categoryArray.count // also tried with 5 or other numbers...

}

func pickerView(pickerView: UIPickerView, viewForRow row: Int,
    forComponent component: Int, reusingView view: UIView!) -> UIView {
        var lab : UILabel!
            if let label = view as? UILabel {
                lab = label
            } else {
                lab = UILabel()
            }
            lab.text = categoryArray[row] // also tried with text like "some test"
            lab.backgroundColor = UIColor.clearColor()
            lab.sizeToFit()
            return lab
}

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
       self.categoryLabel.text = categoryArray[row]
}

设置了 PickerViewDelegate 并创建并连接了所有 socket ... 如果我运行这段代码,它不会从 categoryArray 返回任何值,尽管它已经填充了值。我也尝试手动填充 Picker,但这也没有用。可能是什么原因,任何想法?

最佳答案

感谢大家的评论,我找到了问题...我忘记在 viewDidLoad 中将委托(delegate)设置为 self,我只实现了委托(delegate)类,肯定行不通 ;-)

关于ios - PickerView 不显示任何值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27722048/

相关文章:

ios - 将 Pull to Refresh Control 放在 TableView Header 下

ios - 来自外部脚踏开关的 Cordova 应用程序按键事件在 iOS 上不起作用

ios - 从 CoreData 获取后,单元格中的 UIView 显示错误的颜色

ios - locationManager didUpdateLocations 在设备上触发两次,在模拟器上只触发一次

ios - 使用 NSMutableURLRequest/URLRequest 请求 http

ios - 如何快速在 sceneKit 中连续闪烁 3d 对象?

ios - 滚动时根据下载的图像高度使用 UITableViewAutomaticDimension 调整自定义表格单元格的高度

Xcode:调试所选 View 时无效的变量 View

iphone - 如何检查用户是否已授予特定权限 Facebook iOS

xcode - 如何在Xcode8中 "Delete derived data"?