我收到一个协议不一致的编译器错误。我遗漏了什么?
extension ViewController: UICollectionViewDataSource {
func collectionView(collectionView: UICollectionView!, section: Int) -> Int {
//...
return 5
}
func collectionView(collectionView: UICollectionView!, indexPath: NSIndexPath!) -> UICollectionViewCell! {
let cell: AnyObject = collectionView.dequeueReusableCellWithReuseIdentifier("turkey", forIndexPath:indexPath)
return cell as UICollectionViewCell
//...
}
}
swift:45:1: Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource'发布于 2014-10-01 13:51:25
尝试删除所有!,因为根据文档,委派没有使用可选选项。
发布于 2014-10-02 02:19:12
我只是对所有非可选的API进行了剪切/粘贴并重新编译。
显然,这是可行的。
extension ViewController: UICollectionViewDataSource {
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: AnyObject = collectionView.dequeueReusableCellWithReuseIdentifier("turkey", forIndexPath:indexPath)
return cell as UICollectionViewCell
}
}https://stackoverflow.com/questions/26134850
复制相似问题