我想显示尽可能多的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/336153.html