可選的值在我的自定義的CollectionView細胞我有的UILabel設置文本意外地發現零而展開斯威夫特3
@IBOutlet weak var boardNameLabel: UILabel!
var boardInfoDic: Dictionary? = [String : AnyObject]()
func updateItemAtIndexPath(_ indexPath: NSIndexPath) {
if let string = boardInfoDic?["description"]
{
boardNameLabel.text = String(format: "%@", string as! String)
}
}
,我來自collectionView
cellForItemAt indexPath:
作爲
let boardsCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: KBoardsCollectionViewCellIdentifier, for: indexPath) as! BoardsCollectionViewCell
boardsCollectionViewCell.boardInfoDic = self.boardsDataArray?[indexPath.item] as Dictionary<String, AnyObject>?
boardsCollectionViewCell.updateItemAtIndexPath(indexPath as NSIndexPath)
,但我將數據發送到boardInfoDic我越來越fatal error: unexpectedly found nil while unwrapping an Optional value
,我被嘗試了多種方式,但沒有用。我該如何解決這個問題?與UICollectionViewCell
行更改爲'如果讓字符串= boardInfoDic?[ 「說明」]作爲?字符串「,然後簡單地boardNameLabel.text =字符串。 –
@NiravD更改代碼後我也得到了同樣的錯誤 – SriKanth
@NiravD更新了這個問題,並參考了outlet,我從昨晚開始修復這個問題。 – SriKanth