2017-05-04 13 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を持っています:配列の戻り値はどこで呼び出されますか? –

関連する問題