Bug 12803 - Adding an image to a toolbar item crashes the app
Summary: Adding an image to a toolbar item crashes the app
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 6.3.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-06-20 22:17 UTC by Paul Johnson
Modified: 2013-06-21 04:08 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Paul Johnson 2013-06-20 22:17:03 UTC
Using version (Business Edition) and testing on the simulator

I have a toolbar at the bottom of my view. On this, I have two toolbar items.

When I try to set the item image property, the app crashes completely. I'm using the following code

tbiNewCropPlan.Image = new UIImage(UIImage.FromFile("Graphics/tasks.png"));
tbiNewCropPlan.Title = StringUtils.GetString("PlannedCrops.NewPlan");
tbiUploadServer.Image = new UIImage(UIImage.FromFile("Graphics/more.png"));
tbiUploadServer.Title = StringUtils.GetString("PlannedCrops.Upload");

The images exist and are used elsewhere in the app without a problem.

The crash report that comes back is

[UIImage initWithImage:]: unrecognized selector sent to instance 0x267bf540
Comment 1 Rolf Bjarne Kvinge [MSFT] 2013-06-21 04:08:42 UTC
Looks like we've bound something that doesn't exist in Objective-C.

You can fix this by using the result from UIImage.FromFile directly:

tbiNewCropPlan.Image = UIImage.FromFile("Graphics/tasks.png");
tbiNewCropPlan.Title = StringUtils.GetString("PlannedCrops.NewPlan");
tbiUploadServer.Image = UIImage.FromFile("Graphics/more.png");
tbiUploadServer.Title = StringUtils.GetString("PlannedCrops.Upload");

In future versions of Xamarin.iOS this broken constructor will be removed.

monotouch master-3.0: 796a3219e7d22c7f40d9fdd314d65e54abdd7a3d