gpt4 book ai didi

swift - 即使我为 UICollectionViewDataSource 添加了方法,它也会给我一个错误

转载 作者:行者123 更新时间:2023-11-28 15:46:14 25 4
gpt4 key购买 nike

    //
// ViewController.swift
// CollectionViewTry
//
// Created by Shivam Agrawal on 25/03/17.
// Copyright © 2017 Shivam Agrawal. All rights reserved.
//

import UIKit

class ViewController: UIViewController, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 10, right: 10)
layout.itemSize = CGSize(width: 90, height: 120)

collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
collectionView.dataSource = self
collectionView.delegate = self
collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
collectionView.backgroundColor = UIColor.white
self.view.addSubview(collectionView)






/* print(BigBox.count)
for i in 0...80{
print("\(BigBox[i].identifier) \(BigBox[i].ColID) \(BigBox[i].RowID) \(BigBox[i].SmallBox) \(BigBox[i].sbCount)")
}*/
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 14
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath as IndexPath)
cell.backgroundColor = UIColor.orange
return cell
}

ios 8.1: Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource'

我的问题和上面的类似。我试过并用谷歌搜索,但找不到如何修复我的代码中的错误。尽管我添加了方法,但它说不符合协议(protocol)

最佳答案

函数在你的类之外。因此,它们不是所述类的方法。将它们移入其中。

关于swift - 即使我为 UICollectionViewDataSource 添加了方法,它也会给我一个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43019572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com