ios – 集合视图单元格不显示
2019年11月05日
作者:佚名
我想显示尽可能多的collectionViewCells与按钮,因为我的数组中有字符串.但是当我启动模拟器时,只有CollectionView的背景,没有显示单元格.什么可能是错误?
以下是我在CollectionViewController中附加到main.storyboard中的CollectionView的代码:
class CollectionViewController: UICollectionViewController { var Array = [String]() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. Array = ["1","2","3","4","5"] } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func collectionView(collectionView: UICollectionView,numberOfItemsSection section: Int) -> Int { return Array.count } override func collectionView(collectionView: UICollectionView,cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { var cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell",forIndexPath: indexPath) as! UICollectionViewCell var button = cell.viewWithTag(1) as! UIButton button.titleLabel?.text = Array[indexPath.row] return cell }
}
这些是Collection View Controller的连接:
故事板上的视图控制器:
解决方法
您是否将CollectionViewController设置为故事板身份检查器?
以上是来客网为你收集整理的ios – 集合视图单元格不显示全部内容,希望文章能够帮你解决ios – 集合视图单元格不显示所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。