2016-12-29 63 views
-1

我一直在使用Collection View控制器和2個Table View控制器。我想讓我的第一個桌面視圖控制器在點擊保存按鈕(取消靜音)時將圖像返回到我的集合視圖中。第二臺視圖控制器可以保存兩個圖標圖像。爲什麼我的CollectionView不能返回圖像?

現在,在運行時,我可以看到添加不同單元格(我將灰色背景設置爲單元格),但點擊保存時,但在第二個TableView控制器中選擇的圖像沒有顯示出來,而最終以灰色方塊結束。

代碼在大師系列視圖控制器:

var iconImg = [Icon]() 

override func viewDidLoad() { 
    super.viewDidLoad() 

    // Uncomment the following line to preserve selection between presentations 
    // self.clearsSelectionOnViewWillAppear = false 


    // Do any additional setup after loading the view. 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

// MARK: UICollectionViewDataSource 

override func numberOfSections(in 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 iconImg.count 
} 

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 

    let cellIdentifier = "glanceCell" 
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath) as! MasterCollectionViewCell 

    // Configure the cell 

    return cell 
} 

// MARK: - Navigation 

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 

    if segue.identifier == "ShowIconDetail" { 
     let pickedIconTableViewController = segue.destination as! PickedIconTableViewController 

     // Get the cell that generated this segue 

     if let selectedCell = sender as? MasterCollectionViewCell { 
      let indexPath = collectionView?.indexPath(for: selectedCell)! 
      let selectedIconImage = iconImg[((indexPath)?.item)!] 
      pickedIconTableViewController.iconImage = selectedIconImage 

     } 

    } 

    else if segue.identifier == "AddIcon" { 
     print("Adding new icon") 

    } 

} 

@IBAction func saveToCollectionViewController(_ sender: UIStoryboardSegue) { 

    if let sourceViewController = sender.source as? PickedIconTableViewController, let iconImage = sourceViewController.iconImage { 

     // Add a new icon image. 
     let newIndexPath = IndexPath(item: iconImg.count, section: 0) 
     iconImg.append(iconImage) 
     collectionView?.insertItems(at: [newIndexPath]) 

    } 

} 

@IBAction func cancelToCollectionViewController(_ segue:UIStoryboardSegue) { 

} 

如果誰能告訴我修復應該是什麼,顯示所選圖像,請不要!

+0

對不起Matt ...我發現什麼是錯的!將更新。 – Appy

+0

你說得對,馬特 - 不需要投入太多的代碼。太過分了...... – Appy

回答

0

我是如此專注於unwind segue,我的CellForItemAtIndexPath中的單元格未配置...我遺漏了以下內容:cell.iconImg.image = iconImg [indexPath.row] .icon。謝謝,如果你打擾閱讀:)。

相關問題