- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我现在正在测试 UICollectionViewCell 中有一个变量...这是我的 cellforitem
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let c = collectionView.dequeueReusableCell(withReuseIdentifier: chatCellId, for: indexPath) as! ChatCell
c.userDidSend = (indexPath.item % 2 == 0) ? true : false
return c
}
在 ChatCell 类中,我使用 var userDidSend: Bool? 初始化变量,但是每当我测试变量时,它总是返回 nil。下面是针对每个单元格测试变量的位置。
override func setupViews() {
super.setupViews()
if userDidSend == true {
setupSentChat()
} else if userDidSend == false {
setupRecievedChat()
}
print(userDidSend)
}
除了这个特殊问题之外,一切正常。想法?
编辑:setupViews 在单元格 View 初始化时被调用。
override init(frame: CGRect){
super.init(frame: frame)
setupViews()
}
最佳答案
使用自定义 setter 似乎已经解决了这个问题。
var userDidSend: Bool? {
didSet {
if userDidSend == true {
setupSentChat()
} else if userDidSend == false {
setupRecievedChat()
}
}
}
关于swift - CellForItematIndexPath 无法设置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48855368/
在快速滚动 Collection View 时,我需要动态调整 imagView 的大小... 我使用这个函数来获取滚动事件: func collectionView(collectionVi
我现在正在测试 UICollectionViewCell 中有一个变量...这是我的 cellforitem func collectionView(_ collectionView: UIColle
您能否假设 collectionView:cellForItemAtIndexPath: 何时会被调用?我有一个 UICollectionView,其中每个单元格的大小都与 Collection Vi
这些线上到底发生了什么 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemA
我有一个 UICollectionView,我将它添加到 Storyboard中的 UIViewController 中。 它包含 BookCell 类的 UICollectionViewCell 和
让我描述一下我的问题。 我写了一个名为 CardCell 的类,它继承自 UICollectionViewCell。 在我的另一个类 MainViewController 中,它是 UICollect
我有两个 Collection View 。它们都使用相同的单元格布局,但出于其他原因,它们必须是单独的 Controller 。目前,当我更新 cellForItemAtIndexPath: 时,我
我有一个 UICollectionView,它使用自定义 UICollectionViewCell 类。基本思想是 Collection View 将遍历目录并显示目录中包含的照片(通过 API 调用
我正在尝试从 View Controller 推送到 Collection View Controller 。 UICollectionViewLayout *collectionViewLayout
我有两个 UICollectionViews在我的UIViewController . 假设它们是 A 和 B,A 和 B 在 nib 文件中位于 UIViewcontroller 中的相同位置,它们
我在这个 cellForItemAtIndexPath:(NSIndexPath *)indexPath 上有问题 dispatch_async(dispatch_get_global_q
我读过其他一些关于此问题的问题,这些问题与 CollectionView 的大小有关。我已经尝试按照这些答案中的建议调整大小,但它们都不起作用。我正在使用 NSFetchedResultsContro
我正在构建一个包含大量要在 Collection View 中显示的大型图像文件的应用程序。由于图像的大小,我发现从它们的 URL 创建缩略图以及使用图像缓存要快得多。当我第一次使用 GCD 在 ce
我正在学习 Swift。我有 2 个问题。 完整来源是 here . 1.为什么collectionview(cellForItemAtIndexPath)会这样调用很多次? 编辑:我想知道的是为什么
我正在开发一个带有 UICollectionView 画廊的应用程序。我已将 UICollectionViewFlowLayout 子类化,并已启用 pageEnabled 属性。 我的图库处理图像非
我有一个 UICollectionView,其中每个单元格都是从 Flickr 异步填充的。 在我的场景中,我想要 21 个单元格,我的代码可以很好地生成它。但是,即使在 cellForItemAtI
enter image description here enter image description here 我想隐藏按钮,只要它的标题等于“str”变量即可。 我无法添加更多照片,但它对“7:
我一直想知道为什么我的代码在获取 Collection View 单元格时与 cellForItemAtIndexPath: 一起工作,而不与 dequeueReusableCellWithReuse
所以我正在尝试编写一些代码,将 Collection View 滚动到某个索引,然后提取对单元格的引用并执行一些逻辑。但是我注意到,如果该单元格在滚动之前当前不可见,则 cellForItemAtIn
我有一个更新现有 UICollectionView 的函数。UICollectionView 已创建,我可以看到它,但是当我想访问它的单元格以更新它时,它们为零。 -(void)finishExam{
我是一名优秀的程序员,十分优秀!