Bug 1488 - Images set in a xib in xcode aren't loading at runtime when the xib is loaded from bundle.
Summary: Images set in a xib in xcode aren't loading at runtime when the xib is loaded...
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: iOS add-in ()
Version: 2.8
Hardware: Macintosh Mac OS
: Highest major
Target Milestone: ---
Assignee: Jeffrey Stedfast
URL:
: 1860 3131 ()
Depends on:
Blocks:
 
Reported: 2011-10-13 21:35 UTC by bryan costanich
Modified: 2012-03-28 17:37 UTC (History)
6 users (show)

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


Attachments
repro solution. (4.44 MB, application/zip)
2011-10-13 21:35 UTC, bryan costanich
Details


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:
Status:
RESOLVED FIXED

Description bryan costanich 2011-10-13 21:35:21 UTC
Created attachment 693 [details]
repro solution.

Open attached project. Open Screens/iPhone/Method3SwapViews/LandscapeView_iPhone.xib or PortraitView_iPhone.xib in xcode by double clicking.

notice that image is set.

those views are loaded in loadview depending on orientation:
	public override void LoadView ()
	{
		base.LoadView ();
		
		switch (this.InterfaceOrientation)
		{
			// if we're switchign to landscape
			case UIInterfaceOrientation.LandscapeLeft:
			case UIInterfaceOrientation.LandscapeRight:
				NSBundle.MainBundle.LoadNib ("LandscapeView_iPhone", this, null);
				break;
			
			// we're switch back to portrait
			case UIInterfaceOrientation.Portrait:
			case UIInterfaceOrientation.PortraitUpsideDown:
				NSBundle.MainBundle.LoadNib ("PortraitView_iPhone", this, null);
				break;
		}
	}

however, when you run the app, the images won't load:
2011-10-13 18:15:13.615 HandlingRotation[2493:1907] Could not load the "XamSquare.png" image referenced from a nib in the bundle with identifier "com.yourcompany.handlingrotation"
2011-10-13 18:15:15.465 HandlingRotation[2493:1907] Could not load the "XamSmallSquare.png" image referenced from a nib in the bundle with identifier "com.yourcompany.handlingrotation"
Comment 1 Mikayla Hutchinson [MSFT] 2011-10-13 21:44:27 UTC
You're loading the image as "XamSquare.png", but if you look at the Content file in the project, its bundle resource ID is actually "Images/XamSquare.png".

I suppose this is an issue with the way we export resources to Xcode. If it's not possible to export resources with the full ID, we shouldn't export them, to avoid confusion. Eventually the situation will be improved when I have time to implement the "bundle resource folder" idea I discussed some time back.
Comment 2 bryan costanich 2011-10-13 21:56:27 UTC
hm. sounds like we should get on the bundle resource bit. this is kind of a biggie, since it looks right in xcode, but no one is going to have any idea why it's not working.
Comment 3 Jeffrey Stedfast 2011-11-09 16:18:05 UTC
Looks like the same bug as bug #1860
Comment 4 Jeffrey Stedfast 2011-11-09 16:18:30 UTC
*** Bug 1860 has been marked as a duplicate of this bug. ***
Comment 5 Alan McGovern 2012-01-16 12:43:04 UTC
mhutch, What needs to be done to fix this properly?
Comment 6 Mikayla Hutchinson [MSFT] 2012-01-16 13:46:19 UTC
The best solution would be to figure out a way to make Xcode us the correct ID. If that 's not possible, we shouldn't export images from subdirectories to Xcode.

The bundle resources is a longer term solution. The basic idea is that resources would be in a "Resources" subdirectory. This would be similar to what we do for Android, and would make it possible to add resources to the root of the bundle without polluting the root of the project - which is what people with "Images" directories are trying to do.
Comment 7 Jeffrey Stedfast 2012-01-24 18:35:29 UTC
I tried making our generated project.pbxproj file refer to the resource name as "Image/image.png" (e.g. the relative path from the project root) and Xcode still decided to refer to it as "image.png" in the xib.

So then I tested creating a new project in Xcode, dragging & dropping a folder named "Images" with an image.png file under it into my Xcode project. Xcode referred to this as "image.png" in the .xib as well.

I could find no way of referring to an image resource as anything other than the base name of the filename.

So I guess the only way to fix this is to not support syncing "Content" files from a non-root directory out to Xcode, which is what I've just now committed.
Comment 8 Jeffrey Stedfast 2012-01-30 14:41:22 UTC
*** Bug 3131 has been marked as a duplicate of this bug. ***
Comment 9 Chris Hardy [MSFT] 2012-03-28 17:07:57 UTC
It seems the resolution to this problem is to not support syncing content files which isn't a great solution, I wonder how we can resolve this in a better way.
Comment 10 Mikayla Hutchinson [MSFT] 2012-03-28 17:37:31 UTC
It's not "not support syncing content files", it's "not support syncing 'Content' files from a non-root directory". Since Xcode doesn't appear to support the latter at all, it's simply not possible for us to sync them and have them work correctly.

There's a separate issue for support for structuring project files in "resource directories" in the MD project, yet having them copy to the bundle root. Obviously those *could* be synced to Xcode, once we support them.