2017-05-04 3 views
-3

UITableView에서 인덱스 범위를 벗어나는 문제가 있습니다. 배열의 배열치명적인 오류 : 인덱스가 범위를 벗어났습니다.

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 
     return 50 
    } 

    //== Teble: number of tables ==============================// 
    func numberOfSections(in tableView: UITableView) -> Int { 

     return headerTitleArray.count 
    } 
//== Teble rows: number of rows ==============================// 
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

     return cellTitleMultiArray.count 
    } 

    //== Teble rows: data for each row ==============================// 
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

     let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! CustomTableViewCell 

     let text = cellTitleMultiArray[indexPath.section][indexPath.row] 
     cell.titleLabel.text = text 
     return cell 
    } 


} 

나는이 문제를 해결하기 위해 노력하고 있지만, 내가이 문제를 해결하는 데 도움이 바랍니다 호야 없습니다 .... 그것은 당신의 cellTitleMultiArray처럼 보이는

+0

올바른 'return cellTitleMultiArray.count'입니까? 너는 네가 원하는 것처럼 들린다. 난 그게'return cellTitleMultiArray [section] .count'이어야한다고 생각합니다. –

+2

'return cellTitleMultiArray.count' =>'return cellTitleMultiArray [indexPath.section] .count' – Larme

+0

cellTitleMultiArray [section] .count도 시도했지만 충돌합니다. –

답변

0

된다 다음은 내 코드입니다 외부 배열에는 각 섹션에 대한 항목이 들어 있으며 각 섹션에 대해 해당 인덱스의 내부 배열에는 해당 섹션의 각 행에 대한 항목이 들어 있습니다.

따라서 numberOfSections(in:)cellTitleMultiArray의 항목 수를 반환해야합니다.

tableView(_:numberOfRowsInSection:)은 아마도 현재 섹션의 cellTitleMultiArray 하위 배열에있는 항목 수를 반환해야합니다. 당신이 코드의 비트를 해결할 수 있는지보십시오.

+0

viewForHeaderInSection을 가지고 있습니다. 배열의 반환 값은 어디에서 호출해야합니까? –

관련 문제