嗨!我在UITableView
上遇到問題。我將PickerView
添加到我的textField
的部分行中,如下面的代碼所示。實際上,pickerView
將添加到indexPath.row中的單元格,但不是每個部分。所以這讓我今天早上堅持下去。對不起,我的英語不好。特別感謝您的解決方案。TableView中的每個單元格上的數據重複
這裏是我的代碼:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let data = (self.tableItems[indexPath.section].value?[indexPath.row])!
let identifier : String = data["CELL_IDENTIFIER"]!!
let cell = tableView.dequeueReusableCell(withIdentifier: identifier)
if cell is QuotationHeaderInSectionCell{
let headerCell = cell as! QuotationHeaderInSectionCell
headerCell.lblHeaderInSectionTitle.text = data["TEXT_LABEL"]!!
}else if cell is QuotationItemCell{
let itemCell = cell as! QuotationItemCell
itemCell.lblCellTitle.text = data["TEXT_LABEL"]!!
switch indexPath.section {
case 0:
switch indexPath.row {
case 1:
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: titlePickerView)
break
case 4:
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: genderPickerView)
break
case 10:
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: provincePickerView)
break
case 11:
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: districtPickerView)
break
case 12:
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: communePickerView)
break
case 13:
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: villagePickerView)
break
default:
break
}
break
case 1:
switch indexPath.row {
case 0:
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: assetMakePickerView)
break
case 1:
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: assetRangePickerView)
break
case 2:
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: assetModelPickerView)
break
case 3:
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: assetColorPickerView)
break
default:
break
}
case 2:
if indexPath.row == 0 {
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: dealerPickerView)
}
break
case 3:
switch indexPath.row {
case 0:
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: financeProductPickerView)
break
case 1:
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: advPaymentPercentPickerView)
break
case 3:
self.initInputViewForTextField(sender: itemCell.textFieldCell, inputView: assetColorPickerView)
break
default:
break
}
break
default:
break
}
}else if cell is QuotationCommentCell{
let commentCell = cell as! QuotationCommentCell
commentCell.textViewComment.text = data["TEXT_LABEL"]!!
}else if cell is DocumentTableViewCell{
let documentCell = cell as! DocumentTableViewCell
}
return cell!
}
由於的tableView重用細胞,你可能要考慮具有選擇器視圖作爲細胞的一部分,由故事板原型或通過細胞亞類在裏面。然後有選擇地只顯示它在假設有一個選擇器的單元上。至於選擇器的值,你可以將每個值設置爲一個數組,作爲這個視圖控制器或全局常量的常量。這樣,您無需爲出現的每個單元格添加和刪除視圖。 –
什麼類型的數組爲常量?更多詳細信息plz – Socheat