这可能真的很简单,但我很难尝试让它工作,但本质上是试图使用集合视图来创建网格格式,并在每个单元格中放置播放声音的按钮。
这就是我到目前为止所知道的:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as UICollectionViewCell
var button = cell.viewWithTag(1) as! UIButton
button.setTitle(Array[indexPath.row], forState: UIControlState.Normal)
return cell
}数组是基本的,但这里是:
override func viewDidLoad() {
super.viewDidLoad()
Array = ["apple","berries","dogs"]}我一直在尝试看这个视频(https://www.youtube.com/watch?v=UH3HoPar_xg @大约12分钟左右),但xcode返回了一个错误(致命错误:在打开可选值时意外发现nil )
我现在要做的就是更改按钮标签,使之与数组中的内容相匹配(然后我将重点介绍添加操作)。但是对这个标签有什么建议吗?我必须先进行插座连接吗?如果是这样,为什么视频中的人不需要做一次呢?让我知道,我很感谢任何帮助,谢谢。
忘记提到--故事板上的按钮有一个视图设置为1。
发布于 2016-01-12 14:38:43
确保你的故事板中的以下内容是正确的
https://stackoverflow.com/questions/34734955
复制相似问题