필자는 Collection View 컨트롤러와 2 개의 Table View 컨트롤러로 작업 해 왔습니다. Save 단추 (unwind segue)를 두드리면 내 Collection View로 이미지를 반환하는 첫 번째 Table View 컨트롤러가 필요합니다. 두 번째 테이블 뷰 컨트롤러에는 두 개의 아이콘 이미지가 있습니다.내 CollectionView가 이미지를 반환하지 않는 이유는 무엇입니까?
이제 런타임시 Save를 두 드릴 때 다른 셀이 추가되는 것을 볼 수 있습니다. (셀에 회색 배경을 설정합니다.) 그러나 두 번째 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) {
}
해주세요!
죄송합니다. Matt ... 잘못된 것을 발견했습니다! 업데이트됩니다. – Appy
당신 말이 옳았습니다. Matt - 그 많은 코드를 넣을 필요가 없습니다. – Appy