user3375766
user3375766

Reputation: 31

iAds interfering functionality of Swift app

Since I have enabled iAds in my trivia app, the background, which is supposed to change every time a new question is loaded no longer changes. When I comment out the canDisplayBannerAds line, it works again. Any ideas as to what could be wrong?

import UIKit
import iAd

class ViewController: UIViewController {

    @IBOutlet weak var funFactLabel: UILabel!

    @IBOutlet weak var funFactButton: UIButton!
    let factBook = FactBook()
    let colorWheel = ColorWheel()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        funFactLabel.text = factBook.randomFact()
        self.canDisplayBannerAds = true
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func showFunFact() {
        let randomColor = colorWheel.randomColor()
        view.backgroundColor = randomColor
        funFactButton.tintColor = randomColor
        funFactLabel.text = factBook.randomFact()
    }

}

Upvotes: 3

Views: 31

Answers (1)

David Skrundz
David Skrundz

Reputation: 13347

Rather than using view.backgroundColor = randomColor you should be using originalContentView.backgroundColor = randomColor


How I got the solution:

From the documentation for canDisplayBannerAds

See Also

originalContentView

And originalContentView says:

When a view controller enables banner ads, the system puts the view controller’s content view inside of a new content view that the system manages. This allows the system to dynamically resize the original content view when a banner ad is displayed, as well as managing the display of the banner ad itself. This property provides access to the original content view, rather than the containing view that manages banner ad display.

Upvotes: 1

Related Questions