gpt4 book ai didi

ios - 无法访问单元格 subview Swift

转载 作者:行者123 更新时间:2023-11-28 07:01:46 26 4
gpt4 key购买 nike

我的 UICollectionView 类中有这个函数:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MoreCell", forIndexPath: indexPath) as! UICollectionViewCell

if let icLab = cell.viewWithTag(491) as? UILabel{
icLab.text = moreitems[indexPath.section][indexPath.row].title
}else{
println("Couldnt find label")
}

// Same code for imageView

UICollectionView 的其余部分很好,因为它确实在屏幕上正确显示了单元格,以及初始设置的标签文本(“Label”)

但我似乎无法访问其中的 subview 。以下是它们的设置方式:

enter image description here

而且我确实正确设置了标签和 Cell ID。

有没有人知道为什么它一直在打印 Couldn't find Label

屏幕看起来像这样:

enter image description here

显然,占位符图像和标签未被编辑。

最佳答案

来自苹果的文档

Installed views are added to the view hierarchy. Uninstalled views are not added.

选择标签并选择“已安装enter image description here enter image description here

关于ios - 无法访问单元格 subview Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31856536/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com