所以我想用我的数组像这样设置我的按钮标题,但是结果按钮标题没有显示我的数组
//viewcontroller
let menus = ["Topokki","Sundubu","Galbitang"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return menus.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! CollectionViewCell
cell.menusButton.titleLabel?.text = menus[indexPath.item]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print(indexPath.item)
}
//集合视图单元格类
class CollectionViewCell: UICollectionViewCell {
@IBOutlet weak var menusButton: UIButton!
}
发布于 2019-04-09 03:29:56
尝试:
cell.menusButton.setTitle(menus[indexPath.item], forState: .normal)
https://stackoverflow.com/questions/55580482
复制相似问题