我想显示尽可能多的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设置为故事板身份检查器?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。