1

Say I want to present a UIAlertController:

import UIKit
class ViewController: UIViewController {
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        let alert = UIAlertController(title: "Alert!", message: "Whoops.", preferredStyle: .Alert)
        let dismiss = UIAlertAction(title: "Go back.", style: .Default) { (_) in }
        alert.addAction(dismiss)
        self.presentViewController(alert, animated: true, completion: nil)
    }
}

Elsewhere in the app, I've got a UICollectionView, which I'm styling using UIAppearance in my AppDelegate (best to follow Mattt Thompson's advice):

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    UICollectionViewCell.appearance().backgroundColor = UIColor.blackColor()
    return true
}

This turns the background of the UIAlertAction buttons black, which isn't what I intended.

I tried using the new appearanceWhenContainedInInstancesOfClasses functionality in iOS 9 to restore the default styling...

UICollectionViewCell.appearanceWhenContainedInInstancesOfClasses([UIAlertController.self]).backgroundColor = nil

...but this gives me an EXC_BAD_ACCESS error on that line.

How can I use UICollectionViewCell.appearance(), without disrupting my UIAlertController styling?

Community
  • 1
  • 1
sudo make install
  • 5,629
  • 3
  • 36
  • 48

0 Answers0