gpt4 book ai didi

ios - 标签未出现在 UICollectionView 单元格上方

转载 作者:行者123 更新时间:2023-11-30 12:45:18 25 4
gpt4 key购买 nike

我一直在尝试将标签数组添加到我的 Collection View 单元格中,但它们没有显示。

import UIKit

class HomeMenuViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {

var codes = ["NBA","NFL","Girls","Rappers","Celebrities","NFL Teams","Travel","Models","Foodies","Musician","Companies/Brands","Youtube/Viral Stars","Fitness","Snapchat Art","Fashion/Makeup", "MLB Teams"]

var images = [UIImage(named: "title617792344"),UIImage(named: "title236271662"),UIImage(named: "title713937166"),UIImage(named: "title718520594"),UIImage(named: "title205571580"),UIImage(named: "title193064553"),UIImage(named: "title800939906"),UIImage(named: "title987804505"),UIImage(named: "title528311821"),UIImage(named: "title673858816"),UIImage(named: "title543192229"),UIImage(named: "title351533554"),UIImage(named: "title311505831"),UIImage(named: "title579492173-1"), UIImage(named: "title743923696"),UIImage(named: "title544380635")]

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 16
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

var cell = collectionView.dequeueReusableCell(withReuseIdentifier: "uicvcell", for: indexPath) as! HomeMenuCollectionViewCell

var image = cell.viewWithTag(1) as! UIImageView

image.image = images[indexPath.row]

var code = cell.viewWithTag(2) as! UILabel

code.text = codes [indexPath.row]

return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if(indexPath.row == Int("0")){
performSegue(withIdentifier: "0", sender: nil)
}
else if(indexPath.row == Int("1")){
performSegue(withIdentifier: "1", sender: nil)
}
else if(indexPath.row == Int("2")){
performSegue(withIdentifier: "2", sender: nil)
}
else if(indexPath.row == Int("3")){
performSegue(withIdentifier: "3", sender: nil)
}
else if(indexPath.row == Int("4")){
performSegue(withIdentifier: "4", sender: nil)
}
else if(indexPath.row == Int("5")){
performSegue(withIdentifier: "5", sender: nil)
}
else if(indexPath.row == Int("6")){
performSegue(withIdentifier: "6", sender: nil)
}
else if(indexPath.row == Int("7")){
performSegue(withIdentifier: "7", sender: nil)
}
else if(indexPath.row == Int("8")){
performSegue(withIdentifier: "8", sender: nil)
}
else if(indexPath.row == Int("9")){
performSegue(withIdentifier: "9", sender: nil)
}
else if(indexPath.row == Int("10")){
performSegue(withIdentifier: "10", sender: nil)
}
else if(indexPath.row == Int("11")){
performSegue(withIdentifier: "11", sender: nil)
}
else if(indexPath.row == Int("12")){
performSegue(withIdentifier: "12", sender: nil)
}
else if(indexPath.row == Int("13")){
performSegue(withIdentifier: "13", sender: nil)
}
else if(indexPath.row == Int("14")){
performSegue(withIdentifier: "14", sender: nil)
}
else if(indexPath.row == Int("15")){
performSegue(withIdentifier: "15", sender: nil)
}
else if(indexPath.row == Int("16")){
performSegue(withIdentifier: "16", sender: nil) }
else if(indexPath.row == Int("17")){
performSegue(withIdentifier: "17", sender: nil)
}
else if(indexPath.row == Int("18")){
performSegue(withIdentifier: "18", sender: nil)



}


}
}

这是我的另一个包含 IBOutlets 的文件。

导入UIKit

class HomeMenuCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var codes: UILabel!
@IBOutlet weak var image: UIImageView!


}

我能够在 UICollection View Controller 中执行此操作,但现在我将其添加到 View Controller 中,它不起作用。

最佳答案

@IBOutlet weak var yourCollectionView:UICollectionView!

并将其与主 Storyboard和中的 Collection View 连接起来

ViewDidLoad方法中添加以下行

self.yourCollectionView.delegate = self
self.yourCollectionView.dataSource = self

关于ios - 标签未出现在 UICollectionView 单元格上方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41712878/

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