0
我有一個pickerView由一個標籤和圖像組成。當pickerview被點擊時,我正在更新該圖像。但要顯示圖像的變化,我必須重新加載pickerView。當我重新加載它回到第一行。有沒有辦法重新加載只有特定行的pickerView?在swift中重新加載pickerView的特定行
代碼:
if selectedRows.contains(contactPerson.text!) {
FilteredQuestion_Images[row] = UIImage(named: "Unchecked Checkbox-26")!
let image = FilteredQuestion_Images[row]
imageView = UIImageView(image: image)
if let itemToRemoveIndex = selectedRows.index(of: contactPerson.text!) {
selectedRows.remove(at: itemToRemoveIndex)
ContactPersons_Multiple.remove(at: itemToRemoveIndex)
}
self.dropdownPicker.reloadAllComponents()
}else {
selectedRows.append(contactPerson.text!)
self.imageName = "Checked Checkbox-26"
FilteredQuestion_Images[row] = UIImage(named: "Checked Checkbox-26")!
let image = FilteredQuestion_Images[row]
imageView = UIImageView(image: image)
self.dropdownPicker.reloadAllComponents()
}
}
代碼ViewForRow的:
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let customeView = UIView(frame: CGRect(x: 0, y: 0, width: self.dropdownPicker.rowSize(forComponent: 0).width, height: 30))
// for label
let label = UILabel(frame: CGRect(x: 0, y: 0, width: customeView.frame.width - 35, height: 30))
label.textAlignment = .left
label.text = self.ContactPers[row]
if FilteredContactsSelected == true {
label.text = FilteredContactsNames[row]
}
let image = FilteredQuestion_Images[row]//UIImage(named: imageName)
imageView = UIImageView(image: image)
imageView?.frame = CGRect(x: self.dropdownPicker.rowSize(forComponent: 0).width - 36 , y: 0, width: 26, height: 26)
customeView.addSubview(imageView!)
customeView.addSubview(label)//pickerLabel)
return customeView//pickerLabel
}
在哪裏準確地調用它? –
你實現了'可選公共func pickerView(_ pickerView:UIPickerView,viewForRow行:Int,forComponent組件:Int,重用view:UIView?) - > UIVick'方法'UIPickerViewDelegate'? –
是的,我正在使用它。 –