小编Jho*_*eve的帖子

如何使用UIPicker dataSource

我使用Xcode 8和swift 2.3,但是UIPickerView.dataSource = (self as! UIPickerViewDataSource)当我尝试使用func时,我遇到了一个问题UIPicker,这是我的代码:

import UIKit

class ViewController: UIViewController {

    let Num = ["1","2","3","4","5","6"]

    @IBOutlet weak var UIPicker: UIPickerView!
    override func viewDidLoad() {
        super.viewDidLoad()

        func numberOfRows(inComponent component: Int) -> Int {return 1}

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

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

        UIPicker.dataSource = (self as! UIPickerViewDataSource)
        UIPicker.delegate = (self as! UIPickerViewDelegate)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning() …
Run Code Online (Sandbox Code Playgroud)

swift

3
推荐指数
1
解决办法
4606
查看次数

标签 统计

swift ×1