【发布时间】:2015-10-02 04:30:02
【问题描述】:
如何在单击图像时将数据传递给在集合视图中包含图像的视图控制器到另一个视图控制器?因此,当我单击图像时,它会在另一个视图控制器中打开。
cellForItemAtIndexPath 代码:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CollectionViewCell
cell.imageText.adjustsFontSizeToFitWidth = true
cell.layer.borderWidth = 0.5
cell.layer.cornerRadius = 3
let myColor : UIColor = UIColor(red: 0.0, green: 0.0, blue:0.0, alpha: 0.15)
cell.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.025)
cell.layer.borderColor = myColor.CGColor
let post = self.arrayOfDetails[indexPath.row]
cell.currentUserLabel.text = post.username
cell.imageText.text = post.text
cell.uploadedTimeLabel.text = post.CreatedAt.timeAgo
cell.imageView.setImageWithUrl(NSURL(string: post.image)!, placeHolderImage: UIImage(named: "Placeholder"))
return cell
}
详情:
struct Details {
var username:String!
var text:String!
var CreatedAt:NSDate!
var image:String!
init(username:String,text:String,CreatedAt:NSDate,image:String){
self.username = username
self.text = text
self.CreatedAt = CreatedAt
self.image = image
}
}
didSelectItemAtIndexPath 方法:
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
{
self.performSegueWithIdentifier("showImage", sender: self)
}
有什么建议吗?
【问题讨论】:
-
你的 didSelectItem 方法在哪里?