2017-10-25 5 views
0

私は決してこのプリントを取得しません。これがあるので、あなたはcellForRowメソッドからあなたの携帯を返していない...tableView.cellForRow(at:indexPath)常にnilですか?

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

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

     // Pass data to Cell :) clean the mess at the View Controller ;) 
     cell.restData = items[indexPath.row] 
     // Send cell so it can check update the image to the right cell ;) 
     // cell.cell = tableView.cellForRow(at: indexPath) as? RestCell 
     //print("LA CELDA ES \(tableView.cellForRow(at: indexPath))") 
     if let update = tableView.cellForRow(at: indexPath) as? RestCell { 
     print("VISIBLE CELL") 
     } 

     return cell 
    } 
+0

なぜ 'cellForRowAt'データソースメソッドの中で' cellForRow(at:) 'を呼び出すのですか?あなたはその線で何を達成しようとしていますか? – rmaddy

+0

'cell' **は**あなたが探している細胞です。 – vadian

+0

私はそれについて考えていました。あなたの実際の問題を見てください。https://stackoverflow.com/questions/46901059/uitableviewcell-subclass-wrong-image-in-cell-or -old-image-bug –

答えて

0

/

if let update = tableView.cellForRow(at: indexPath) as? RestCell { 
       print("VISIBLE CELL") 
       } 

完全なコードを:それは常にnilであるように、私はそれをスクロールアップまたはダウンどのくらいの問題doesntのif文がfalseを返す理由。なぜあなたはこれをやろうとしているのか分かりませんが、よりよい方法が必要です。可視セルを探したい場合は、UITableView visibleCells変数を使用できます。

+0

お返事ありがとうございます。実際の問題をここで確認してください... https://stackoverflow.com/questions/46901059/uitableviewcell-subclass-wrong-image-in-cell-or-old-image-bug –

+0

im実際に私のuitableviewcellサブクラスですべてを設定しようとすると、何が起こっているのは、接続が正しくないときに、正しく設定される前に間違ったセルに設定されてしまうことです。 –

+0

これは、セルがメモリを節約するために再利用されているためです。あなたのUITableVieCellサブクラスでメソッド "prepareForReuse"をオーバーライドし、ダウンロードイメージタスクをキャンセルします。非常に一般的な問題;) –

関連する問題