2017-08-16 13 views
0

私は致命的なエラーを下に行くと、セルを埋めるために次のコードがあります。私はそれがセルのキャッチnilの配列の値のために私かもしれないことを観察する。TableView indexPath致命的なエラー:インデックスが範囲外です

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") as UITableViewCell! 

    // Set text from the data model 
    cell.textLabel?.text = values[indexPath.row] 
    cell.textLabel?.font = textField.font 

    return cell 
} 

func numberOfSections(in tableView: UITableView) -> Int { 
    return 1 
} 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return values.count; 
} 
+0

値の配列が範囲外である可能性があります。 – koropok

+0

'numberOfRows'メソッドのコードを追加 – Jaydeep

+4

バックグラウンドスレッドで' values'配列を更新していますか? –

答えて

0

この機能は、1つのセクションのみを使用する場合に使用します。

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return values.count 
} 

複数のセクションでも同様の回避策があります。 を過ぎたvaluesの値に決してアクセスしないようにしてください。

+0

は既にそこに私の編集された投稿をチェックする – Fou

関連する問題