func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cellTop = tableView.dequeueReusableCell(withIdentifier: "ArticleTopTableViewCell", for:indexPath) as! ArticleTopTableViewCell let cell = tableView.dequeueReusableCell(withIdentifier: "ArticleTableViewCell", for:indexPath) as! ArticleTableViewCell let article = articles[indexPath.row] if indexPath.row == 0 { cellTop.configure(article: article) } else { cell.configure(article: article) } return cell or cellTopを返したい }
一つのセクションで二つのカスタムセルを使いたく、イメージとしては上記のようなことを実装したいのですが、やり方がわかりません。
どなたかアドバイスいただけないでしょうか?
以下のコードでは'Attempted to dequeue multiple cells for the same index path, which is not allowed. If you really need to dequeue more cells than the table view is requestingと言われてしまいました。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let article = articles[indexPath.row] let cell = tableView.dequeueReusableCell(withIdentifier: "ArticleTableViewCell", for:indexPath) as! ArticleTableViewCell if finishedLoading { if indexPath.row == 0 { let cellTop = tableView.dequeueReusableCell(withIdentifier: "ArticleTopTableViewCell", for:indexPath) as! ArticleTopTableViewCell cellTop.configure(article: article) return cellTop } cell.configure(article: article) } return cell }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/08/03 12:55
2018/08/03 12:59
退会済みユーザー
2018/08/03 13:06
2018/08/03 13:12