我查找了很多示例并尝试合并但未成功。在我的CollectionView(已被放置在ViewController中)中,我想选择一个单元格并将单元格图像推送到另一个ViewController。图像已放置在字典数组中。我不知道,我该如何编辑我的prepareForSegue或我的func collectionView ... didSelectItemAtIndexPath。此外,随着您的代码的任何详细解释将会有所帮助,因为我仍然在快速学习它的语法。如何将图像从CollectionView传输/显示到另一个ViewController
下面是我认为你需要的所有信息,但请让我知道如果你需要更多:
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "ShowToStory") {
var story = sender as! UICollectionViewCell, indexPath = collectionView.indexPathForCell(story)
}
}
private func initStoryImages() {
var storyArchives = [StoryImages]()
let inputFile = NSBundle.mainBundle().pathForResource("StoryArchive", ofType: "plist")
let inputDataArray = NSArray(contentsOfFile: inputFile!)
for inputItem in inputDataArray as! [Dictionary<String, String>] {
let storyImage = StoryImages(dataDictionary: inputItem)
storyArchives.append(storyImage)
}
storyImages = storyArchives
}
额外类别:CollectionViewCell类
class CollectionViewCell: UICollectionViewCell {
@IBOutlet weak var cellImage: UIImageView!
func setStoryImage(item:StoryImages){
cellImage.image = UIImage(named:item.itemImage)
}
}
额外类别:UIViewController中
class StoryView: UIViewController{
@IBOutlet weak var ImageToStory: UIImageView!
var story: StoryImages?
override func viewDidLoad() {
super.viewDidLoad()
ImageToStory.image = UIImage(named: (story?.itemImage)!)
}
}
ADDITIONAL CLASS:StoryImages
class StoryImages{
var itemImage: String
init(dataDictionary:Dictionary <String,String>) {
itemImage = dataDictionary["ItemImage"]!
}
class func newStoryImage(dataDictionary:Dictionary<String,String>) -> StoryImages {
return StoryImages(dataDictionary: dataDictionary)
}
}
}
你的segue与'UICollectionViewCell'或'ViewController'连接吗? –
从哪里显示新的viewController来显示图像?????? –
@Nirav我的segue连接到ViewController – Ojay