UIViewController and Native Ads on TableView

340 views
Skip to first unread message

Natsios Kwnstantinos

unread,
Dec 1, 2016, 7:39:47 PM12/1/16
to Google Mobile Ads SDK Developers
Hello.
Is there any way to make the example work with UIViewController (with a tableview inside) instead of TableViewController?

I've completed my application as the example (also with the correct admob pub and google info plist from firebase) But it only shows the regular cells from my Class and it never enters at this lines of code

```
func tableView(_ tableView: UITableView,
                            cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if let nativeExpressAdView = taEvent[indexPath.row] as? GADNativeExpressAdView {
            let reusableAdCell = tableView.dequeueReusableCell(withIdentifier: "NativeExpressAdViewCell",
                                                               for: indexPath)
            
            // Remove previous GADNativeExpressAdView from the content view before adding a new one.
            for subview in reusableAdCell.contentView.subviews {
                subview.removeFromSuperview()
            }
            print("test")   // ITS NEVER PRINTED AS SCROLLING
            reusableAdCell.contentView.addSubview(nativeExpressAdView)
            // Center GADNativeExpressAdView in the table cell's content view.
            nativeExpressAdView.center = reusableAdCell.contentView.center
            
            return reusableAdCell
    
        } else {
                
            let cell = tableView.dequeueReusableCell(withIdentifier: "locationCell", for: indexPath) as? EventsTableViewCell
                
                            let event = taEvent[indexPath.row]
                            cell?.configureCell(events: event as! Events)
                            return cell!
            }
    }
```
And i think its because of the `reloaddata` that i use.
Any idea?

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Dec 2, 2016, 11:22:57 AM12/2/16
to Google Mobile Ads SDK Developers
Hi Natsios,

I have a sample app that shows how you can integrate ads in a UITableViewCell with the UITableViewController added onto a UIViewController. Let us know if that help you. If not, you can send us your own sample app and we would be able to help you with the implementation.

Thanks,
Arjun Busani
Mobile Ads SDK Team

Natsios Kwnstantinos

unread,
Dec 2, 2016, 1:01:33 PM12/2/16
to Google Mobile Ads SDK Developers
Hello and thanks for the help.
I've managed to fix it.
It was my initial thought that the reload data of the table was executing first, and the table view was completed. So the 2 functions even if they run, they couldnt be appended at the indexPath.row cause all the rows were full.

In this case all i did was to make this

 DispatchQueue.main.async{
                                self.addNativeExpressAds()
                                
                                self.locationTable.reloadData()
                                self.preloadNextAd()
                            
                            }

Although if you have a way to make something as a "promise" to first load the ad and then reload the data i would be grateful !
Reply all
Reply to author
Forward
0 new messages