I have a simple button to be added to a UINavigationBar, Min OS is 3.2 and we compile with the default compiler. I have MT 5.0:
saleImg = UIImage.FromFileUncached (shoppingImg);
saleButton = new UIBarButtonItem ("", UIBarButtonItemStyle.Bordered, (s, o) => {ItunesHelper.Open (); });
saleButton.SetBackgroundImage(saleImg,UIControlState.Normal,UIBarMetrics.Default);
saleButton.SetBackgroundImage(saleImg,UIControlState.Selected, UIBarMetrics.Default);
saleButton.SetBackgroundImage(saleImg,UIControlState.Highlighted, UIBarMetrics.Default);
But when run it throws the error:
Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[UIBarButtonItem setBackgroundImage:forState:barMetrics:]: unrecognized selector sent to instance 0x76d4d00
The
UIBarButtonItem.SetBackgroundImagemethod was introduced with iOS 5. Since you are getting an “unrecognized selector…” message, I can only assume that you are running the app on a device with an iOS version older than 5.0.If you want your app to be backwards compatible, create a button and initialize the
UIBarButtonItemwith theUIBarButtonItem(UIView)constructor:Setting the minimum OS version does not mean that MonoDevelop or the compiler will inform you of API compatibilities. It is merely a setting in Info.plist which will determine if your app will appear on the App Store for devices of that version or not.