1
當我嘗試使用.count添加newItem時,什麼都不顯示。當我使用它替換「汽車」,我沒有看到它在pickerview中,也需要上下滾動幾次newItem出現之前。如何在swift中爲UIPickerview的2分量數組添加新元素
var picker1 = String()
var picker2 = String()
var pickerViewArray = [["Items", "car"], ["Action", "Turn", "Hit", "Pull", "Scrape"]]
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return pickerViewArray.count
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerViewArray[component].count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerViewArray[component][row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
picker1 = pickerViewArray[0] [pickerView.selectedRow(inComponent: 0)] + ""
picker2 = pickerViewArray[1] [pickerView.selectedRow(inComponent: 1)] + ""
}
func addItemsToArray() {
stringWall = "Wall"
addItemAtIndex = pickerViewArray[0].count
pickerViewArray[0].insert(newItem, at: addItemAtIndex)
allRoomArray[arraySelector][wallButton] = stringWall
pickingRooms()
print(newItem)
}
我不認爲脂肪酶你這樣想的。通常,我將創建一個帶有自定義「UITableViewCell」的UITableView來完成動態列表。 'UIPickerView'是相當有預定義的,並沒有太多的動態視圖。 – antonio081014
感謝您的回答。你給出的最好建議是,它不是爲了做我想做的事。 – Dmar