swift - 带有来自数组的文本标签的 UICollectionView
问题描述
我试图有一个显示一系列客户推荐的集合视图。我在内容视图上有另一个集合视图,这就是为什么下面的部分代码包含一个图像集合视图。该应用程序在我的手机上运行良好,但标签未显示在屏幕上。我究竟做错了什么?
@IBOutlet weak var collectionViewTwo: UICollectionView!
let testimonialArray = ["You rock", "You suck"]
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView.tag == 1 {
let cell = collectionViewOne.dequeueReusableCell(withReuseIdentifier: "HomeOneCollectionViewCell", for: indexPath) as? HomeOneCollectionViewCell
cell!.imageOne.image = imageArrayOne[indexPath.row]
return cell!
} else {
let cell = collectionViewTwo.dequeueReusableCell(withReuseIdentifier: "HomeTwoCollectionViewCell", for: indexPath) as? HomeTwoCollectionViewCell
cell?.testimonialLabel?.text = testimonialArray[indexPath.row]
cell?.testimonialLabel?.textColor = UIColor.white
return cell!
}
}
解决方案
猜猜你错误地将文本颜色设置为白色?白色标签不会显示在白色背景上。评论该行应该向您显示结果。粉煤灰。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView.tag == 1 {
let cell = collectionViewOne.dequeueReusableCell(withReuseIdentifier: "HomeOneCollectionViewCell", for: indexPath) as? HomeOneCollectionViewCell
cell!.imageOne.image = imageArrayOne[indexPath.row]
return cell!
} else {
let cell = collectionViewTwo.dequeueReusableCell(withReuseIdentifier: "HomeTwoCollectionViewCell", for: indexPath) as? HomeTwoCollectionViewCell
cell?.testimonialLabel?.text = testimonialArray[indexPath.row]
// cell?.testimonialLabel?.textColor = UIColor.white
return cell!
}
}
推荐阅读
- qt - 2 个不同 QML 文件中的 2 个不同对象之间的通信
- javascript - php Ajax文件上传,总是出现未定义索引错误
- c++ - 正则表达式搜索不接受参数
- python - 正则表达式匹配变量字符后的字符串
- ruby-on-rails - 如何将密码箱 gem 与 ransack gem 一起使用?
- delphi - 将 SmallInt 常量定义为十六进制
- android - 当媒体记录器开始录制视频时,Camera.PreviewCallback 的“onPreviewFrame”方法停止工作
- java - 如何在应用程序中包含大型字符串数组资源?
- php - 我刚刚在我的 macbook 中激活了 php,但它说的是权限错误
- javascript - 如果未包装,则JQuery将字符串的每个单词包装在span中