我看到帖子的情侶,但沒能找出問題問題從UicollectionView控制器
我想從UICollectionView控制器的數據傳遞給我的UIViewController傳遞數據,下面是詳細信息
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "Selection2" {
if let indexPath = self.collectionView?.indexPath(for: sender as! UICollectionViewCell) {
let detailVC = segue.destination as! SelectionViewController
//
let item = items1[indexPath.row]
//passing the item name which is selected
detailVC.label1.text = item.name1
}
}
}
這裏是SelectionViewController代碼:
import UIKit
class SelctionViewController: UIViewController {
var label1 : UILabel!
@IBOutlet weak var Label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
Label.text = self.label1.text
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
但是,當我運行這個我不能夠傳遞價值和得到以下錯誤:
致命錯誤:意外發現零而展開的可選值
請建議如何得以糾正,謝謝
我會說,或者'sender'不是'UICollectionViewCell'或'segue.destination'不是'SelectionViewController'。你可以添加一個異常斷點來查看應用程序崩潰的位置嗎? –