我正在用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