私は、n番目(3番目)のセルごとに異なるセル(Ad)を表示しようとしています。このよう :スウィフトUITableView異なるN番目のセル
"Request"
"Request"
"Request"
"Ad"
"Request"
"Request"
"Request"
"Ad"
"Request"
"Request"
"Request"
"Ad"
"Request"
...
マイコード:
ものが私の変数
var requests = [RequestListable]()
var list = [Listable]()
var users = [UserInfo?]()
var adInterval = 3
私は広告をロードしようとしている私の機能だ
です。問題は通常、すべてのリクエスト(requestsArray)には1つの関連付けられたユーザー(usersArray)があり、「listArray」に広告を挿入するときに、ユーザーはもうリクエストと一致しないということです。どういたしまして。 そのため、広告が挿入されている同じインデックスにfakeUserを挿入していますが、それは機能しません。ものは、私のテーブルビュー機能です私は私の 要求
func loadAds() { Api.adApi.observeAds { (ad, user) in self.list = self.requests for i in stride(from: self.adInterval, to: self.requests.count, by: self.adInterval).reversed() { self.list.insert(ad, at: i) self.users.insert(user, at: i) // This is probably where i'ts going wrong print(self.users.count) // Returns 40 (Don't know why) print(self.list.count) // Returns 13 } } }
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return list.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let listing = list[indexPath.row]
if let request = listing as? RequestListable
{
let cell = tableView.dequeueReusableCell(withIdentifier: "RequestCell", for: indexPath) as! RequestTVCell
let user = users[indexPath.row]
cell.request = request
cell.user = user
cell.delegate = self
return cell
}
else if let ad = listing as? AdListable
{
let cell = tableView.dequeueReusableCell(withIdentifier: "AdCell", for: indexPath) as! AdTVCell
cell.ad = ad
cell.user = users[indexPath.row]
return cell
}
fatalError("Did not find data or ad for cell: Should never get here")
}
だから問題があるフェッチ異なる機能、でテーブルビューをリロードしています:
人のユーザーが広告とユーザー
任意の提案を挿入 た後、それに関連する要求に合致していませんか?私は本当にそれを感謝します。