こちらのソースコードを使って棒グラフを描画したいのですが、
collectionView?.register(Barcell.self, forCellWithReuseIdentifier: cellId)にUse of unresolved identifier 'Barcell'; did you mean 'strcoll'?のエラー、
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! BarCellにUse of undeclared type 'BarCell'のエラーが出てしまいます。
おそらくソースコードが古いんだと思いますがズブの素人なのでわかりません。もっといいソースコード等ありましたら教えてもらいたいです。
class ViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout { let cellId = "cellId" let values: [CGFloat] = [200, 300, 400, 500, 600, 700, 50, 20, 10, 5, 650, 2000, 3000, 500] override func viewDidLoad() { super.viewDidLoad() collectionView?.backgroundColor = .white collectionView?.register(Barcell.self, forCellWithReuseIdentifier: cellId) (collectionView?.collectionViewLayout as? UICollectionViewFlowLayout)?.scrollDirection = .horizontal } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { return 4 } override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return values.count } func maxHeight() -> CGFloat { return view.frame.height - 20 - 44 - 8 } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! BarCell if let max = values.max() { let value = values[indexPath.item] let ratio = value / max cell.barHeightConstraint?.constant = maxHeight() * ratio } return cell } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize(width: 30, height: maxHeight()) } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { return UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 4) } } ```
「swift 3.0 で書かれたグラフを描画するソースコード」はどこから持ってきたのでしょうか?Swift5とは関係のない箇所でエラーが出ているように見えますが。
あなたの回答
tips
プレビュー