mridul ghanshala
mridul ghanshala

Reputation: 51

MDC crashing with 'NSInvalidArgumentException', reason: '-[UIButton applyOutlinedThemeWithScheme:]: unrecognized selector sent to instance

I am trying to set a button property like this, When i add this code it crashes without even displaying the button i have in the main.storyboard.

 let containerScheme = MDCContainerScheme()
        cancelButton.applyOutlinedTheme(withScheme: containerScheme)

console

Upvotes: 0

Views: 1919

Answers (2)

dronpopdev
dronpopdev

Reputation: 817

I faced the same problem. But I was building the UI through code.

import MaterialComponents.MaterialButtons
import MaterialComponents.MaterialButtons_Theming

let button = MDCButton()
button.applyTextTheme(withScheme: MDCContainerScheme())

The following helped me. I just called the option Product -> Clean Build Folder. After that, the abnormal termination of the program disappeared.

Upvotes: 1

Bill
Bill

Reputation: 469

From the error, you can see that UIButton does not have a method called applyOutlinedThemeWithScheme, which could mean that in your storyboard or XIB, you are using a UIButton instead of a MDCButton.

In your storyboard or XIB, go to Identity Inspector, make sure Class is set to MDCButton.

Upvotes: 0

Related Questions