私の目標は、セクションを使用しているUITableViewにNative Express広告を表示することです。 10th TOTALセル(すべてのセクションのセルを組み合わせる)は、ネイティブ・エクスペリエンス広告でなければなりません。他のすべてのセルは通常のセルになります。Native Express広告がUITableView内に表示されない
問題はありません。広告は表示されません。問題は私のcellForRowAtキャストにあると思う。私はAndrew Brogdonのチュートリアルに続きました。https://www.youtube.com/watch?v=chNb7-k6m4M - 私が混乱している部分は5:10マークの周りにあります。
私は私のコード細胞が両方FruitObjectsを保持することができるようにANYOBJECTとしてobjectsArrayをキャストし、GADNativeExpressAdView
ています:
クラス:
struct FruitObjects {
var sectionName: String!
var sectionObjects: [FruitModel]!
}
var objectsArray = [AnyObject]()
のviewDidLoad:
をobjectsArray = [
FruitObjects(sectionName: "A", sectionObjects: [
FruitModel(fruitTerm: "Apple", definition: "Lorem Ipsum Dolor Sit Amet."),
FruitModel(fruitTerm: "Apple 2", definition: "Lorem Ipsum Dolor Sit Amet."),
FruitModel(fruitTerm: "Apple 3", definition: "Lorem Ipsum Dolor Sit Amet.")
]) as AnyObject,
FruitObjects(sectionName: "B", sectionObjects: [
FruitModel(fruitTerm: "Banana", definition: "Lorem Ipsum Dolor Sit Amet."),
FruitModel(fruitTerm: "Banana 2", definition: "Lorem Ipsum Dolor Sit Amet."),
FruitModel(fruitTerm: "Banana 3", definition: "Lorem Ipsum Dolor Sit Amet.")
]) as AnyObject,
FruitObjects(sectionName: "C", sectionObjects: [
FruitModel(fruitTerm: "Clementine", definition: "Lorem Ipsum Dolor Sit Amet."),
FruitModel(fruitTerm: "Clementine 2", definition: "Lorem Ipsum Dolor Sit Amet.")
]) as AnyObject
]
UITableViewDataSource:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let myCast = objectsArray[section] as? FruitObjects
return myCast!.sectionObjects.count
}
func numberOfSections(in tableView: UITableView) -> Int {
return objectsArray.count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let myCast = objectsArray[section] as? FruitObjects
return myCast!.sectionName
}
cellForRowAt:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let myCast = objectsArray[indexPath.section] as? FruitObjects{
let cell = tableView.dequeueReusableCell(withIdentifier: "CellID", for: indexPath)
cell.textLabel?.text = myCast.sectionObjects[indexPath.row].fruitTerm
print("CELL")
return cell
}
else {
let adView = objectsArray[indexPath.row] as! GADNativeExpressAdView
let reusableAdCell = tableView.dequeueReusableCell(withIdentifier: "NativeExpressAdViewCellReuseID", for: indexPath)
// MISSING removeFromSuperview https://www.youtube.com/watch?v=chNb7-k6m4M 5:51
reusableAdCell.contentView.addSubview(adView)
adView.center = reusableAdCell.contentView.center
print("NATIVE")
}
}
あなたは私がすべての10番目のセルを示すネイティブ広告を得るのを助けることはできますか?
私は上記のコードに問題があると考えています。おそらく私のキャスティングで?何も気にならないように見えたら、私に知らせて、私はViewControllerの詳細を投稿します。
ご協力いただきありがとうございます。
またfunc nativeExpressAdViewDidReceiveAd(_ nativeExpressAdView: GADNativeExpressAdView) { }