2个PickerViews在同一个ViewController上 - titleForRow基金"将不被执行"

时间:2017-03-29 12:01:07

标签: ios swift3 tags uipickerview

我已经标记了PickerViews 1和2,但我得到了一个"不会被执行"关于func titleForRow的消息,我该如何解决?

@IBOutlet weak var shoeDetailPic: UIImageView!
@IBOutlet weak var shoeDetailName: UILabel!
@IBOutlet weak var shoeDetailPrice: UILabel!
@IBOutlet weak var shoeColourPickerView: UIPickerView!
@IBOutlet weak var shoeSizePickerView: UIPickerView!

var pickerColour = [""]
var pickerSize = [""]

var getName = String()
var getPrice = String()
var getImage = UIImage()


override func viewDidLoad() {
super.viewDidLoad()


shoeDetailPic.image = getImage
shoeDetailName.text = getName
shoeDetailPrice.text = getPrice

pickerColour = ["Gold", "Black", "Red"]
pickerSize = ["35", "36", "37", "38", "39", "40", "41", "42"]

}




override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

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

}

func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component:   Int) -> Int {
    if (pickerView.tag == 1){
        return pickerColour.count
    }else{
        return pickerSize.count
    }

此处的消息 - 不会被执行。是否与IBOutlet名称有关?

  func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent    component: Int) -> String?{
        if (pickerView.tag == 1){
            return "\(pickerColour[row])"
        }else{
            return "\(pickerSize[row])"
        }

}
}
}

1 个答案:

答案 0 :(得分:1)

问题是你将myFun :: _ => a -> w a constrainedFun :: (_, RealConstraint a) => a -> b a 委托方法放在titleForRow中,它应该在该方法之外作为类的实例方法。

numberOfRowsInComponent

注意:您已经为func numberOfComponents(in pickerView: UIPickerView) -> Int { return 1 } func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { if (pickerView == shoeColourPickerView){ return pickerColour.count }else{ return pickerSize.count } } func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { if (pickerView == shoeColourPickerView){ return pickerColour[row] }else{ return pickerSize[row] } } 创建了商店,而不是在委托方法中比较pickerView,如果您与商店进行比较,那么它就会受到影响。