我试图将一个图像数组从UICollectionViewController转移到带有静态单元格的UITableViewController。设置是当用户按下集合视图控制器中的单元格时,该单元格中的UIImage将切换到表视图控制器中的UIImageView。
问题是图片没有出现在UITableViewController
的{{1}}中。
我认为UIImageView
未传递给UIImage
中的UIImageView
。
以下是我的相关UITableViewController
代码:
UICollectionViewController
以下是我的相关import UIKit
private let reuseIdentifier = "Cell"
class AddImageCollectionViewController: UICollectionViewController {
var mainImages = ["cup", "transport", "beach", "weather", "gear", "money", "technology-1", "web", "people", "nature", "draw", "technology", "screen", "shop", "arrow"]
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: UICollectionViewDataSource
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 mainImages.count
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let screenSize = UIScreen.mainScreen().bounds
let screenWidth = screenSize.width / 3
let screenHeight = screenWidth
let size = CGSize(width: screenWidth, height: screenHeight)
return size
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! AddImageCollectionViewCell
// Configure the cell
cell.mainImageView.image = UIImage(named: mainImages[indexPath.row])
return cell
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
collectionView?.reloadData()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "nextStep" {
if let indexPaths = collectionView?.indexPathsForSelectedItems() {
let destinationViewController = segue.destinationViewController as! AddTableViewController
//let photoViewController = destinationViewController.viewControllers[0] as! PhotoViewController
destinationViewController.imageName = mainImages[indexPaths[0].row]
}
}
}
}
代码:
UITableViewController
在模拟器中的Collection View Controller中选择我的单元格后,我在控制台中收到以下错误消息:
CUICatalog:提供的资产名称无效: