質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

0回答

135閲覧

swift 3.0 で書かれたグラフを描画するソースコードをどうやってswift5.0.1で使うか

madeinrachel

総合スコア12

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2019/05/27 15:24

こちらのソースコードを使って棒グラフを描画したいのですが、
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) } } ```

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

takabosoft

2019/05/28 07:59 編集

「swift 3.0 で書かれたグラフを描画するソースコード」はどこから持ってきたのでしょうか?Swift5とは関係のない箇所でエラーが出ているように見えますが。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問