Why does resource bundle copy .png as .tiff images? - iphone

I've created a static library and a resource bundle for reusing code and assets across several projects.
Within the static library, I have a manager class whose sole purpose is to create other UIViewControllers, whose views are created from .xib files (using the common initWithNibName:bundle: method).
When I create the view in Interface Builder, the images show correctly. However, when I run the app on the simulator, I get this error:
Could not load the "<image_name.png>" image referenced from a nib in the
bundle with identifier "com.<my_company>.<app_identifer>"
After hours of grinding, I finally inspected the resources bundle, and I found that the .png files weren't in it! Instead, .tiff files of the same name (excluding #2x versions) were there instead.
All of the images are included within the bundle's build phase under copy bundle resources , and I've used the images on other iOS projects (so they're not corrupted).
Has anyone else experienced this? Is it safe to assume that the images will always be added to the bundle as .tiff? (And if so, is it safe to just change the image name in interface builder to .tiff?) Or am I doing something incorrect here?
Thanks for your help in advance.

For the issue of resource bundles , refer to this link as it has a couple of similar faced queries.
Conversion Resource bundle
Tell me which answer really helped you solve this issue. Thanks.

This Solved my problem
In your bundle target Go to,
Build Settings > COMBINE_HIDPI_IMAGES and set to NO

Related

iOS: How to use images in custom bundle in Interface Builder?

I have a bundle where i put images in it.
The contents are:
MyBundle.bundle/images/picture1.png
MyBundle.bundle/images/picture2.png
I dragged MyBundle.bundle into my project.
Now I can see these images in Interface Builder and can even use them. However, when I run the app, I don't see the images.
What's wrong?
Thanks,
Make sure the bundle is getting copied over in the "Build Phases" of the project settings for the target.
Also, try setting them progrmatically and see if they show:
myImageView.image = [UIImage imageNamed:#"MyBundle.bundle/images/picture1.png"];
I just tried this in my project and found that what you need to do is specify the image with the bundle name in front like this:
In the IB the image will look broken:
but when you build and run your project the image will show correctly.
So, in your case, use MyBundle.bundle/images/picture1.png in the actual Interface Builder Image box.
Also, when you dont put the bundle name in front, you get this warning when you load the view with the bundle image:
2011-10-12 08:22:16.360 UTDebug[721:11c03] Could not load the "map.png" image referenced from a nib in the bundle with identifier "com.companyname.myproject"
You need to put the XIB in the bundle, too. When you do that, resources for the interface will be relative to the bundle, so they'll work both in IB and when you load the interface in your app.
You might have a stray build setting from having created the bundle as a Mac OS X target.
See my other answer for the solution.

Core-Plot: Unknown class CPLayerHostingView in Interface Builder file

Using core-plot does not seem to be an easy integration task. Header path are already setup. In Interface-Builder I create an CPLayerHostingView which belongs to a View Controller which is instantiated by Interface Builder.
When the nib file is loaded I get the message:
Unknown class CPLayerHostingView in Interface Builder file
I found, that there are two different versions of that object. One for Mac-Only called "CPLayerHostingView", one for iPhone only called "CPGraphHostingView".
If following the poplular example at http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application you would use the following lines, if building an iPhone-App:
CPGraphHostingView *graphView = (CPGraphHostingView*)self.view;
graphView.hostedGraph = graph;
http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application
Here is the answer ..
U can see mars' answer there
"i got it to work....ok, i added the -all_load -ObjC flag in the Target>Settings....I think this is where everyone gets confused...There are 2 places where to put the other link and header search paths, in Project Settings and in Target Settings.."
So solution is
Add -all_load -ObjC in Project settings and target settings
I had to rename CPLayerHostingView to CPGraphHostingView to get this to work after upgrading to the latest version of core plot (along with iOS 4 and the upgrade of XCode).
I think you're saying that you get this error when you load the NIB file in your app's code. In that case, the error suggests that you haven't built the Core Plot classes into your application (iPhone) or linked against the CorePlot framework and copied into the app bundle's Frameworks/ directory (OS X).
CPGraphHostingView
thank u it worked for me aswell;
3 imp things
1>perform settings for both project target aswell as application target.(make sure configuration is all configuration)
2>give correct header search path for framework library
3>learn over it::::::-)
For whatever it is worth.
Followed tutorial: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application and ended up having that same error. I looked into the CorePlot framework folder and did not find that CPLayerHostingView there, but found CPGraphHostingView inside iPhoneOnly folder.
Changed CPLayerHostingView to CPGraphHostingView in IB and error disappeared.
So, check what is in yours and use it. May work.

Images in Interface Builder when using MonoTouch

I'm new to MonoTouch and iPhone development. I have my images (PNG) in a resources folder in MonoDevelop, however if I want to set the image property for a button in Interface Builder, how do I do that? It's always a blank dropdown. Do I need to use XCode to access the XIB file and then somehow embed the button image file I'll need in it?
This is a known limitation of MonoDevelop and Interface Builder. To add images to an XIB in Interface Builder they must be part of an XCode project, which of course coming from MonoDevelop they're not.
To achieve what you're trying to do you will need to set the image via code, and ensure the build action of your image is set to Content. To do this, simply right click your image inside MonoDevelop, and select Build Action > Content.
On your view with the button on it, create an outlet in Interface Builder for your button, hook it up, then from code to set your image, you just need to use the .FromFile("path/name") method of UIImage.
UIImage buttonImage = UIImage.FromFile ("resources/image.png");
myButton.SetBackgroundImage (buttonImage,UIControlState.Normal);
That's off the top of my head, but I think that should do it.
You can manually set the image in Interface Builder, but it wont show up until run time. The image name can include a path, e.g. "images/settings.png".
All solutions given here are completely wrong and misleading. All you need to do, is place your images in the Resources folder (on the project root), and add your images to this folder. After adding files to this folder, mark all files and make sure their build action is set to BundleResource.
I also needed this to work, here is a workaround I found.
You need to create a dummy xcode project. Place it in the same folder as your project.
Add all your xib files and image files to that xcode project by dragging them in when the project is opened in xcode. Now you will be able to see the preview of the images.
The image files must be in the same folder as the project file and xcode must be opened with the dummy project while the interface builder is opened.
Not great - but solves the issue for now.
Here is a sample project I have created.
For this issue to be resolved on the MonoDevelop side - some inter-process communication code needs to be created, I think that a good starting point will be looking for "PBXProjectWatcherServerConnection-3.1.2" in google.

iPhone simulator shows app's images but iPhone does not

I have create an application on iphone using objective-c.In this application i am just displaying different players images stored in one folder, which will be run perfectly on simulator. But when I deploy it on iphone it is not showing the images of the player.
for that the code is:
UIImageView *imageplayer = [[UIImageView alloc]initWithFrame: CGRectMake(imgx, imgy+45,135,150)];
imageplayer.image = [UIImage imageNamed:playerpng];
if(imageplayer.image == nil)
[imageplayer setImage:[UIImage imageNamed:playerjpg]];
if(imageplayer.image == nil)
[imageplayer setImage:[UIImage imageNamed:#"noimage.png"]];
[self.view addSubView:imageplayer];
Plz solve this query.
Thanks in advance
Sometimes xCode doesent update correctly the bundle, try cleaning and building again.
I am currently experiencing this problem as well. I was able to correct it after a bit of debugging and reviewing the build file.
When I do an ls -l, I noticed that some of my png files have a # symbol beside the permissions. When I followed that up with a ls -l#, it showed that the files with an '#' had an attribute set 'com.apple.quarantine'. This attribute is given to a file (often from a zip, jar, or other executable) that is downloaded from the net. You can get rid of this attribute by performing:
xattr -d com.apple.quarantine *.png
Then, select the images in XCode, and check that the checkbox under the target is checked. In my case, it was not, so the images weren't being included in the bundle.
I had the same problem, solved by using all lowercase for the file name in code - image.jpg, but it does not seem to make any difference what case the actual file name is, e.g. Image.jpg
check name of image file. It must be "noimage.png"
not Noimage.png or noimage.PNG
Just to clarify, does the "noimage.png" display, or is the program loading a player image but failing to display it? Or is nothing loading.
These should easily be determined in debug mode.
A few additional things to check...
1) Just for testing, start out with PNG versions of the player files. This is the primary format on the iPhone and might eliminate a file format issue or other anomaly that the simulator is not sensitive to.
2) With regard to fixing in an image editor, specifically make sure that the image is set to a DPI of 72 pixels/inch. The iPhone and particularly Interface Builder are very sensitive to this being correct and will sometimes not display or will display a very blurred version of the image if incorrect.
3) Make sure the image(s) haven't been added multiple times (from different directories and/or to different group folders). We encountered a situation where we had inadvertently imported the same images at two different layers within the project hierarchy and this can cause unexpected behavior within the iPhone (selecting randomly or failing to select).
4) Make sure the Get Info -> Targets has your particular target checked. The simulator may still see the image but it will not get deployed to the iPhone.
5) Make sure you can view the image within XCode and that it looks correct.
Barney
This happens to me sometimes. I once spent half a night trying to figure out what was wrong. In this end, this is what worked: open the image with an image editor and save it again. That's all. I'm using the free Acorn image editor to do this. Haven't tried it with Photoshop. (After all, it seems that Photoshop might be responsible for introducing the error in the first place, although that's far from sure.)
I don't know what causes the problem. I usually get it when I use png files that have been sent to me. Could be a simple file permissions problem, or some more subtle problem with the image format. I would be very interested in hearing the opinion of better-informed people.
In any case, if all else fails just try this: open the image with Acorn, save over the original file. Works for me.
Make sure the image files are added to your XCode project.
After some investigation, Michael's comment seems to have a solved it for me. I had all lower case as the file name but was following variable convention and had the png file with an upper case for the second part of the file name. Here my file was putback.png but was referenced in my code as putBack.png
UIImage *putBackImage = [UIImage imageNamed:#"putBack.png"]; //wrong
UIImage *putBackImage = [UIImage imageNamed:#"putback.png"]; //correct
Select correct target while adding image files to your project. Following are steps to make it further clear
Select Add Files to "YourProjectName"
In opening window there is an "Add to targets" option at bottom that shows all available targets
Check target or multiple targets in which you want to add images
Press "Add" button and you are ready to go

Packaging a Bundle with a static library

I have a static library that includes some xibs. These will basically be the same across projects. I'd like to include the xibs as part of the library. I can include their veiwcontrollers, reference these controllers in the calling project but then there isn't a xib to load. When I right click the xib in the library project, it can't be part of the target.
I thought about creating a CFPluginBundle but that creates a new project. I'd loose all of my IBOutlet and IBAction references. What is the best way to reuse xibs that also have outlets and actions to specific controllers?
Here more discussion about it: Can you reference Xib files from static libraries on the iPhone?
I had the same problem when I wanted to export my project as a library for other developers to use.
I found the perfect solution to my view and it seems it will answer yours too.
There is an xcode plugin that allows you to build your project as a library which includes the resources as well.
https://github.com/kstenerud/iOS-Universal-Framework
I do not know the guys that built this plugin, but it works like a charm
I'm not sure what you mean by "include the xibs as part of the library", since static libraries can't have resources--but they also aren't shipped stand-alone, so they don't need to. If you just want code re-use for your own projects, you could keep the xibs where-ever you keep the static library, and just include the xibs in any project that uses the library.
If you go the CFPluginBundle route, you can make new bundle targets in an existing project; there's nothing magic about the templates, they just take care of making dummy files and turning on the right build settings. You can copy those into a new target in your existing project and it will work just fine. That said, I'm not sure what you mean about losing IBOutlet and IBAction references, since that information is part of the xib (and the class you are using in the xib), not the project.