我正在用Swift構建iOS應用程序,其中用戶可以上下滾動瀏覽圖像(如instagram),也可以在單元格上向左或向右滾動看更多的圖像。請參閱this album(尚不能上傳圖像)並查看F1如何佈置UI。UIScrollView在影響其他單元格中UIScrollView位置的可重用單元格中的位置
我的問題是當我滾動到圖像1C時,第三個單元格也滾動到3C。所以當我向下滾動到第三個單元時,它已經在3C了。見F2。
另外,如果我滾動第三個單元格到3B,它也會將第一個單元格重新定位到1B。見F3。
我想了解一些幫助這是怎麼回事...
我已經創建了細胞的自定義類的函數加載圖像。 (這裏我也初始化ImageView的幀,滾動視圖框架和內容的大小和其他特性,這我不包括在下面的代碼。)
class CustomCell: UITableViewCell {
var imageView1: UIImageView = UIImageView()
var imageView2: UIImageView = UIImageView()
var imageView3: UIImageView = UIImageView()
func loadImages(#image1: String, image2: String, image3: String){
imageView1.image = UIImage(named: image1)
imageView2.image = UIImage(named: image2)
imageView3.image = UIImage(named: image3)
}}
,並在我的視圖控制器 - 的cellForRowAtIndexPath
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:CustomCell = self.tableView.dequeueReusableCellWithIdentifier("CustomCell") as CustomCell
var (firstImage, secondImage, thirdImage) = images[indexPath.row]
cell.loadImages(image1: firstImage, image2: secondImage, image3: thirdImage)
return cell
}
僅供參考:這看起來只在視圖是根視圖控制器時發生。視圖已經呈現時,它工作正常。 ???
謝謝!
謝謝!在哪個函數中最好保存該單元格的偏移量?的cellForRowAtIndexPath?然後,我會在單元格的prepareForReuse函數中設置適當的contentOffset嗎? – MaxB 2015-02-18 01:23:51