###実現したいこと
タイトルがまとまっていなくてすみません。
インスタグラムのようなタイムラインを作ってみようと思っています。
UITableViewを使用し、各Cellの中にUIScrollViewで作ったスライドショーみたいなものを設置して再現をしています。
pull to refreshをすると先頭にcellが追加されてreloadData()されます。
###発生している問題
1. 一つ目のCellで2枚目の画像までスライドし、pull to refreshをすると新しいCellは追加されるのですが、
新しい方が2枚目までスライドされている状態で、2枚目までスライドした方は1枚目に戻ってしまいまう。
2. 複数Cellがある状態で一つ目のCellを2枚目の画像までスライドすると四つ目のCellでも2枚目までスライドされている。
Cellが四つ離れていると同じ現象が必ず起こる。
1つ目,4つ目
2つ目,5つ目
3つ目,6つ目
のような関係
###試したこと
UITableView + Cacheをつかってキャッシュしてみた。
今は使っていません。
###補足情報
・ Swift3
・ CellはカスタムCellを使っています
・ 画像はSDWebImageでキャッシュしています
###解決?
swift
1 var imagePageCount:Dictionary<Int, CGFloat> = [:] 2 var imageScrollView:Dictionary<Int, CGRect> = [:] 3 4 internal func tableView(_ tableView: UITableView, cellForRowAt indexPath:IndexPath) -> UITableViewCell { 5 print("セルを作った") 6 let cell: TimelineCell = tableView.dequeueReusableCell(withIdentifier: "TimelineCell", for: indexPath as IndexPath) as! TimelineCell 7 8 cell.setCell(timeline: timelineData[indexPath.row]) 9 10 if (imageScrollViewData[indexPath.row] != nil) { 11 cell.imageScrollView.contentOffset.x = imagePageCount[indexPath.row]! 12 cell.imageScrollView.frame = imageScrollView:Dictionary[indexPath.row]! 13 } 14 15 return cell 16 } 17 18 func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { 19 print("画面外にでた") 20 let cell: TimelineCell = tableView.dequeueReusableCell(withIdentifier: "TimelineCell", for: indexPath as IndexPath) as! TimelineCell 21 imagePageCount[indexPath.row] = cell.imageScrollView.contentOffset.x 22 imageScrollView:Dictionary[indexPath.row] = cell.imageScrollView.frame 23 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/30 04:49
2017/06/30 04:51 編集
2017/06/30 04:58
2017/06/30 05:32