【发布时间】:2016-07-27 02:04:22
【问题描述】:
我查找了许多示例并尝试合并,但均未成功。在我的 CollectionView(已放置在 ViewController 中)中,我想选择一个单元格并将单元格图像推送到另一个 ViewController。对图像的引用已放置在 plist 文件中的字典数组中。我不确定,我应该如何编辑我的 prepareForSegue 或我的 func collectionView...didSelectItemAtIndexPath。此外,任何与您的代码相关的详细解释都会有所帮助,因为我仍在学习 swift 及其语法。
以下是我认为您需要的所有信息,但如果您需要更多信息,请告诉我:
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 (Edit_1)
class StoryView: UIViewController{
@IBOutlet weak var ImageToStory: UIImageView!
var story: Story?
override func viewWillAppear(animated: Bool) {
if let story = story {
ImageToStory.image = UIImage(named: story.imageName)
}
}
}
【问题讨论】:
标签: swift segue viewcontroller collectionview