Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionViewCell内的UILabel为零_Ios_Swift_Uicollectionviewcell_Iboutlet - Fatal编程技术网

Ios UICollectionViewCell内的UILabel为零

Ios UICollectionViewCell内的UILabel为零,ios,swift,uicollectionviewcell,iboutlet,Ios,Swift,Uicollectionviewcell,Iboutlet,设置值时,UICollectionViewCell内的标签为零。使用故事板中的自定义单元格,因此不在viewDidLoad中注册。下面是我的代码: func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell

设置值时,UICollectionViewCell内的标签为零。使用故事板中的自定义单元格,因此不在viewDidLoad中注册。下面是我的代码:

 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CalenderCell", for: indexPath) as! CalenderCollectionViewCell
    
   
    if let label = cell.lblDayName{
        label.text = arrCalendarDates[indexPath.item] // crashing here thus used if let to avoid crash but it is nil, Why so?
    }
   
    return cell
}
更新:

class CalenderCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var lblDayName: UILabel!

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}


您应该检查
@IBOutlet
是否连接到故事板中预期的
UILabel

检查dequeueReusableCellWithReuseIdentifier中的reuseIdentifier与故事板中的reuseIdentifier是否相同。是否在单元中连接了插座
lblDayName
?是,都已检查,正确的标识符和连接的插座,否则如果让它进入,它会崩溃吗?如果是,那么不是标签,而是零。尝试arrCalendarDates[indexPath.row]是否将单元格注册到集合视图?它已连接,先生,也已重新检查。这可能是愚蠢的。在这种情况下,您确定
@IBOutlet
连接到正确的目标
UICollectionViewCell
子类,而不是
UIViewController
子类吗?是的,共享,自定义类,更新了问题