【发布时间】:2015-11-30 20:02:05
【问题描述】:
我对 Swift 比较陌生,遇到了这个问题,这个问题可能很容易解决,我就是想不通,一直碰壁。
我正在制作一个应用程序,其中用户在集合视图控制器中点击图像,它会执行展开转回主视图控制器并使用用户选择的图像更新 uiimageview。我得到了展开 segue 的工作,但问题是 uiimageview 总是在后面一个图像(即我选择图像 A,展开 segue 并且没有图像显示,所以我选择图像 B 展开 segue 然后我选择了原始图像第一次,图像 A 在 uiimageview 中)。
这是目标视图控制器的代码(我希望 uiimageview 根据集合视图中选择的图像更新的主视图控制器)...
@IBAction func unwindToVC(segue:UIStoryboardSegue) {
if(segue.sourceViewController .isKindOfClass(FrancoCollectionCollectionViewController))
{
let francoCollectionView:FrancoCollectionCollectionViewController = segue.sourceViewController as! FrancoCollectionCollectionViewController
let selectedImageFromLibrary = selectedFranco
dragImage!.image = UIImage(named: selectedImageFromLibrary)
}
在用户选择图像并展开的集合视图控制器上,我只是 ctrl + 将单元格拖动到情节提要上的“退出”并选择了 unwindToVC segue。
就我的集合视图而言,我是如何设置的,因为我怀疑它与它的 didSelectItemAtIndexPath 部分有关,但我不确定......
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
return francoPhotos.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! FrancoCellCollectionViewCell
// sets each cell of collection view to be a uiimage view of francoPhotos
let image = UIImage(named: francoPhotos[indexPath.row])
cell.francoImageCell.image = image
return cell
}
// highlights cell when touched
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
selectedFranco = francoPhotos[indexPath.row]
let cell = collectionView.cellForItemAtIndexPath(indexPath)
cell!.layer.borderWidth = 3.0
cell!.layer.borderColor = UIColor.blueColor().CGColor
}
override func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)
cell!.layer.borderWidth = 0.0
cell!.layer.borderColor = UIColor.clearColor().CGColor
}
抱歉,如果我发布了太多代码,但这是我的第一篇文章,就像我说我是开发新手一样,所以我认为包含一些额外的东西比没有需要的东西更好。
非常感谢任何建议!
非常感谢!!! :)
【问题讨论】:
-
不确定这是否会有所帮助,因为这对于 SO 来说是一个很大的问题。解决这个问题可能需要做很多工作。但是在展开之后,如何在collectionView 上重新加载呢?因此,在 viewwillappear 或 viewdidappear 或 viewdidlayoutsubviews 或其他一些自定义方法中,您调用在 collectionview 中重新加载
-
凯特,当你说你碰壁时,具体是什么问题?
标签: ios swift uiimageview uicollectionview unwind-segue