ใครเขียน swift IOS ช่วยเข้ามาช่วยแก้ หรือให้คำแนะนำ หน่อยค่ะ
ถ้าเราใส่ return pShipmentCategories[selected].count ตอน Run Project
มันจะฟ้อง Fatal error: Index out of range
แต่ถ้าเราปรับโค้ดเป็น return pShipmentCategories.count Run ได้มันพอเลือกวันที่ มันก็เด้ง Fatal error: Index out of range
ตรงตัวหนังสือสีแดง
Run Value From Postman - Plandate function http://xxx.xxx.xxx.xx/ProjectService/PODService.svc/GetPlanDate/2
"[ { \"PlanDate\": \"26/08/2019\", \"PlanDateFullFormat\": \"20190826\" }, { \"PlanDate\": \"27/08/2019\", \"PlanDateFullFormat\": \"20190827\" }]"
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 2
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if component == 0 {
return pPlandateCategories.count
}else{
let selected = pickerview.selectedRow(inComponent:0)
return pShipmentCategories[selected].count ———>. Thread 1: Fatal error: Index out of range
}
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if component == 0 {
return pPlandateCategories[row]
}else{
let selected = pickerview.selectedRow(inComponent:0)
return pShipmentCategories[selected][row]
}
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if component == 0{
pickerview.reloadComponent(1)
}else{
let selected = pickerview.selectedRow(inComponent:0)
someTextField.text = "Shipment:" + " " + pShipmentCategories[selected][row]
}
}
Error when Run Project
//////////////-getPlanDate-/////////////////
urlcheckPlanDate ==> http://xxx.xxx.xxx.xx/ProjectService/PODService.svc/GetPlanDate/2GetPlanDate/2
Fatal error: Index out of range
2019-12-19 10:55:14.459056+0700 pickerDateAndShipment[782:19020] Fatal error: Index out of range
Tag : Mobile, Ms SQL Server 2016, iOS, iPhone, Swift, Web Services