func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return interests.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt cellForItemAtindexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(Storyboard.CellIdentifier, forIndexPath:indexPath) as! InterestCollectionViewCell
cell.interest = self.interest[indexPath.item]
return cell
}
-1
A
回答
0
改成這樣:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(Storyboard.CellIdentifier, forIndexPath:indexPath) as! InterestCollectionViewCell
cell.interest = self.interest[indexPath.item]
return cell
}
UPDATE
如果這是你還需要添加的UICollectionView功能override
關鍵字之前func
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(Storyboard.CellIdentifier, forIndexPath:indexPath) as! InterestCollectionViewCell
cell.interest = self.interest[indexPath.item]
return cell
}
2
糾正你的方法簽名
斯威夫特
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
目標C
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
0
extension ViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return interests.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Storyboard.cellIdentifier, for: indexPath) as! InterestCollectionViewCell
cell.interest = interests[(indexPath as NSIndexPath).item]
return cell
}
}
+0
你能請格式化代碼正確嗎?看起來好像您需要將所有行縮進四個空格 – huwr
0
//MARK:- extension of collection view
extension CreateTapUpFirstVC : UICollectionViewDelegate, UICollectionViewDataSource , UICollectionViewDelegateFlowLayout{
// MARK: - Collection View delegate & datasource
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return arrCategory.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TappUpCell", for: indexPath as IndexPath) as! TappUpCell
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
let bounds = UIScreen.main.bounds
let height = bounds.size.height
if(height == 736) {
// return UIEdgeInsetsMake(top, left, bottom, right);
return UIEdgeInsetsMake(20, 40, 20, 40)
} else if(height == 667){
return UIEdgeInsetsMake(20, 40, 20, 40)
} else if(height == 568) {
return UIEdgeInsetsMake(20, 20, 10, 20)
} else if(height == 480) {
return UIEdgeInsetsMake(20, 20, 10, 20)
} else {
return UIEdgeInsetsMake(20, 40, 20, 40)
}
}
func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,minimumLineSpacingForSectionAt section: Int) -> CGFloat {
let bounds = UIScreen.main.bounds
// let width = bounds.size.width
let height = bounds.size.height
if(height == 736) {
return 10//20
} else if(height == 667){
return 5//15
} else {
return 5//10
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 100.0, height: 100.0);
}
}
相關問題
- 1. 斯威夫特2:OBJC_ASSOCIATION_RETAIN_NONATOMIC使用未解決的標識符
- 2. 使用未解決的標識符「showAlert」斯威夫特
- 3. 斯威夫特3使用未解決的標識符「clearColor」
- 4. 使用未解決的標識符「LAContext」斯威夫特3
- 5. 未解決的標識符表(斯威夫特2)
- 6. 斯威夫特錯誤:未解決的標識符「NSLayoutAttributeWidth」
- 7. 斯威夫特3個懸而未決的標識符CGColorGetComponents
- 8. 使用未解決的標識符「metadataItems」
- 9. 使用未解決的標識符
- 10. 使用未解決的標識符「MYIMAGE」
- 11. 斯威夫特錯誤:信號SIGABRT如何解決它
- 12. 如何解決未解決的符號?
- 13. 解析JSON使用斯威夫特/ SwiftyJSON
- 14. 使用JSON解析器斯威夫特
- 15. 未解決的標識符範圍
- 16. swift 3中未解決的標識符
- 17. IndexPath斯威夫特的TableView點擊列
- 18. 解碼base64 +解密 - 斯威夫特
- 19. 未解決標識符錯誤Swift
- 20. 使用未解決的標識符「NSURLRequestUseProtocolCachePolicy」在SWIFT 2
- 21. 斯威夫特解析:在_user
- 22. 空間在斯威夫特斯威夫特的標記語言
- 23. 使用中未解決的標識符「UITextBorderStyleRoundedRect」的迅速
- 24. 使用的未解決的標識符「信息」蘋果教程
- 25. 試圖解析斯威夫特4 HTML僅使用標準庫
- 26. 使用未解決的標識符 「成功」 與SwiftyStoreKit
- 27. 使用未解決的標識符「SKStoreReviewController」,但已經
- 28. 使用未解決的標識符錯誤代碼
- 29. 「未解決的標識符使用‘myAlert&okAction’
- 30. swift build使用未解決的標識符
你的方法沒有'indexPath' PARAM – aircraft