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

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

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

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

Q&A

解決済

1回答

221閲覧

テーブルビューのセルの表示カスタマイズ

gamak

総合スコア3

Swift

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

0グッド

0クリップ

投稿2021/08/29 03:56

解決したこと

https://qiita.com/shige52070/items/6408c77914a28ab1cd8e
このサイトを見てセルのカスタムをし実行しFirstCustomCellView, SecondCustomCellView, SerdCustomCelllViewの順で表示されたのですがこれをFirstCustomCellView, SecondCustomCellView, SerdCustomCelllView, serdCustomViewCell, serdCustomViewCell...と三番目のセルだけをたくさん表示するにはどのように書けばよろしいですか?

試したこと

for文で量産しようとしたこと
私と同じ質問をしている人を見つけようとしたこと

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

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

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

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

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

hoshi-takanori

2021/08/29 04:42

Serd って何だろう? と思ったら元の記事もそうなってますね。3 番目は英語で Third です。 それはさておき、 ・numberOfRowsInSection で、First の個数 + Second の個数 + Third の個数を返す ・ cellForRowAt で、indexPath.row に応じて適切なセルを返す とすれば良いのですが、enum Cell の使い方を調整する必要がありますね。
guest

回答1

0

ベストアンサー

最小限の修正案として
Cellinitを以下のように実装して

Swift

1 enum Cell: CaseIterable { 2 case firstCustomViewCell 3 case secondCustomViewCell 4 case sardCustomViewCell 5 6 var cellIdentifier: String { 7 switch self { 8 case .firstCustomViewCell: 9 return "FirstCustomViewCell" 10 case .secondCustomViewCell: 11 return "SecondCustomViewCell" 12 case .sardCustomViewCell: 13 return "SardCustomViewCell" 14 } 15 } 16 17 init(_ row: Int) { 18 switch row { 19 case 1: 20 self = .firstCustomViewCell 21 case 2: 22 self = .secondCustomViewCell 23 default: 24 self = .sardCustomViewCell 25 } 26 } 27 }

cellForRowAtのcellTypeを生成しているところをCell(indexPath.row)に書き換えれば行けます。

Swift

1 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 2// let cellType = Cell(rawValue: indexPath.row) 3 let cellType = Cell(indexPath.row) 4 switch cellType { 5 case .firstCustomViewCell: 6 let cell = tableView.dequeueReusableCell(withIdentifier: cellType.cellIdentifier) as! FirstCustomViewCell 7 return cell 8 case .secondCustomViewCell: 9 let cell = tableView.dequeueReusableCell(withIdentifier: cellType.cellIdentifier) as! SecondCustomViewCell 10 return cell 11 case .sardCustomViewCell: 12 let cell = tableView.dequeueReusableCell(withIdentifier: cellType.cellIdentifier) as! SardCustomViewCell 13 return cell 14 } 15 }

投稿2021/08/30 06:14

shiokara

総合スコア95

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問