ActionPickerView获取结果

时间:2017-04-24 12:09:07

标签: swift uipickerview

我有一个与按钮链接的pickerView 当你点击按钮时它会出现..

我的问题是: 我不知道如何获得结果并将其打印到我创建的textFiled ..

如果我可以在按钮名称中生成结果而不需要文本提交将会很棒!!

这就是我到目前为止所做的:

import UIKit
import ActionSheetPicker_3_0


class ViewController2: UIViewController {

@IBOutlet weak var text1: UITextField!
@IBAction func ssss(_ sender: Any) {


    ActionSheetMultipleStringPicker.show(withTitle: "Multiple String Picker", rows: [
        ["One", "Two", "A lot"],
        ], initialSelection: [1],

           doneBlock: {


            picker, indexes, values in


            self.text1.text = ("\(values)")

            /**
            print("values = \(values)")
            print("indexes = \(indexes)")
            print("picker = \(picker)")
            return
**/

    },


           cancel: { ActionMultipleStringCancelBlock in return }, origin: sender)


}

1 个答案:

答案 0 :(得分:0)

我认为在将值分配给文本字段时,doneBlock中的变量名称出错了。另外,请查看initialSelection参数。您已提供[1],它将选择整个数组。

 ActionSheetMultipleStringPicker.show(
      withTitle: "Multiple String Picker", 
      rows: [["One", "Two", "A lot"]], 
      initialSelection: [1, 1],
      doneBlock: { picker, indexes, values in
        // self.text1.text = ("\(vslues)")
        // should be
        self.text1.text = ("\(values)")
      },
      cancel: { ActionMultipleStringCancelBlock in return }, 
      origin: sender)