いつもお世話になります。
複数のcollectionViewを画面上に置く場合の func collectionView cellForItemAt を記述したのですが、下記のreturnが無いよというエラーが消えなくて困っています。なにが原因でしょうか?
swift
1Missing return in a function expected to return 'UICollectionViewCell'
swift
1func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 2 if collectionView.tag == 1 { 3 let aCell = collectionView.dequeueReusableCell(withReuseIdentifier: "ALapTimeCell", for: indexPath) as! ACollectionViewCell 4 aLapTimeDetail = aLapTimeArray[indexPath.item + 1] 5 let lapNum = String(indexPath.item + 1) + ":" 6 let lapTime = aLapTimeDetail[0] 7 let lapSplit = aLapTimeDetail[1] 8 aCell.setLapTimeLabel(lapNum: lapNum, lapTime: lapTime, lapSplit: lapSplit) 9 return aCell 10 } else if collectionView.tag == 2 { 11 let bCell = collectionView.dequeueReusableCell(withReuseIdentifier: "BLapTimeCell", for: indexPath) as! BCollectionViewCell 12 bLapTimeDetail = bLapTimeArray[indexPath.item + 1] 13 let lapNum = String(indexPath.item + 1) + ":" 14 let lapTime = bLapTimeDetail[0] 15 let lapSplit = bLapTimeDetail[1] 16 bCell.setLapTimeLabel(lapNum: lapNum, lapTime: lapTime, lapSplit: lapSplit) 17 return bCell 18 } 19 } //=> Missing return in a function expected to return 'UICollectionViewCell'
collectionViewの他のfunctionも同じように記述して下記のようなエラーが出てしまいます。
numberOfItemsInSection => Missing return in a function expected to return 'Int'
collectionViewLayout => Missing return in a function expected to return 'CGSize'
複数のtableViewではこのような書き方でエラーは出なかったのですが、collectionViewでは同じようにできないのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/07/04 14:34 編集