PDA

View Full Version : Problem with xCode please help!




Soulstorm
Feb 20, 2006, 12:03 PM
I am programming on carbon framework with xcode 2.2. I am a total beginner in this.

And I want to include an image in a simple window. No buttons, no other stuff

So, I make a resource file from this image uusing graphic converter. I go to my project, and I add the .rsrc file in the "Resources" folder.

I open my .nib file with Interface Builder and I include the image in the main window. I click "Test interface" from the menu of interface builder and everything seems normal.

But when I compile my entire program with XCode, the image does not appear in the window!!

I went to the package contents of my newly built application and saw my .rsrc file in there, only it had 0kbytes size!

What can I do? Am I doing something wrong?

EDIT: Repaired perimissions, updated prebindings, rotated logs and still the same problem...
EDIT2: I tested the same method into another machine and I had the same problem. Is it a bug, or I am making something wrong?



iSee
Feb 20, 2006, 12:52 PM
Your .rsrc file could be losing its resource fork when it is copied as part of the build process. That would explain its size (0) and the fact that it isn't displayed (.rsrc files have all their content in the resource fork).

You could:
1. Use a different image format that stores the image data in the data fork (png, jpeg)--whatever will work with xcode & interface builder.
2. Find the build step that copies your .rsrc into the package and make sure it preserves resouce forks. I've never poked around in xcode's build process, so I have no help to offer you here.

Soulstorm
Feb 20, 2006, 12:57 PM
Your .rsrc file could be losing its resource fork when it is copied as part of the build process. That would explain its size (0) and the fact that it isn't displayed (.rsrc files have all their content in the resource fork).

You could:
1. Use a different image format that stores the image data in the data fork (png, jpeg)--whatever will work with xcode & interface builder.
2. Find the build step that copies your .rsrc into the package and make sure it preserves resouce forks. I've never poked around in xcode's build process, so I have no help to offer you here.
every time that I save a file with an .rsrc extension, it is a PICT resource file. How can I make a resource file that contains .png? Can you show me a program that will help me?

EDIT: Maybe I should rephrase it:
How do I add images into my carbon application? What type must me those images, how do I create them, and what steps do I need to follow in Interface builder?

GeeYouEye
Feb 20, 2006, 01:06 PM
Don't save it as a resource file, simple as that. Save/export it as a PNG.

Soulstorm
Feb 20, 2006, 01:12 PM
Don't save it as a resource file, simple as that. Save/export it as a PNG.

Excuse my ignorance, but as you can see I am a total noob, and my book ("Mac OS X programming by Dan Parks Sydow") only explains what I must do with resources, and doesn't say anything for any other file types.

I tried what you said too. After that, what do i need to do?

I go to my project, and I with right-click, I add the .png file to my project, in the "resources" folder. But when I open Interface builder, it doesn't show me the image I want to use. How do I use this .png file?

Can you explain me exactly what must I do? And why the expected result is shown in the interface builder when I test my interface, but not in the final program????

Soulstorm
Feb 20, 2006, 01:27 PM
OK now I'm really worried. I did the same thing with a resource file that came directly from apple's example files. It didn't work. It showed the expected result in the Interface Builder, but the final program was missing the resource file...

Help. :mad:

iSee
Feb 20, 2006, 01:49 PM
every time that I save a file with an .rsrc extension, it is a PICT resource file. How can I make a resource file that contains .png? Can you show me a program that will help me?

EDIT: Maybe I should rephrase it:
How do I add images into my carbon application? What type must me those images, how do I create them, and what steps do I need to follow in Interface builder?

Hmm... I was working with a .nib for a cocoa app, where I could just drag-and-drop a .png file into the images tab of image builder. But this doesn't seem to work the same way for Carbon .nib files. I can't see how to add a .png to a carbon .nib. According to Interface Builder help:
Generally, the images are not stored in the nib file itself. Instead, the Images pane displays images that are in the same Project Builder target as the nib file is in. If the nib file is in multiple targets, Interface Builder includes only those images that are in all those targets
This doesn't seem to be the whole story though. I added a .png (and a PICT) to the one-and-only target in a test carbon project. It does not show up in the images tab. Sorry, I don't see how this is supposed to work...

Soulstorm
Feb 20, 2006, 01:57 PM
Hmm... I was working with a .nib for a cocoa app, where I could just drag-and-drop a .png file into the images tab of image builder. But this doesn't seem to work the same way for Carbon .nib files. I can't see how to add a .png to a carbon .nib. According to Interface Builder help:

This doesn't seem to be the whole story though. I added a .png (and a PICT) to the one-and-only target in a test carbon project. It does not show up in the images tab. Sorry, I don't see how this is supposed to work...
at least have you managed to import a resource file to the carbon application? Can it happen, or am I not the only one that has the problem?

gekko513
Feb 20, 2006, 02:03 PM
Is the resource in the Resources folder in the main Xcode window?

If it isn't try to drag it there.

Soulstorm
Feb 20, 2006, 02:08 PM
Is the resource in the Resources folder in the main Xcode window?

If it isn't try to drag it there.
Yes it is. I think I already mentioned it in my first post. :)

gekko513
Feb 20, 2006, 02:27 PM
Yes it is. I think I already mentioned it in my first post. :)
That you did. Sorry about that. :o

What happens if you don't add it in Xcode but only choose File -> Import -> Import Resource File in Interface Builder.

Soulstorm
Feb 20, 2006, 02:38 PM
That you did. Sorry about that. :o

What happens if you don't add it in Xcode but only choose File -> Import -> Import Resource File in Interface Builder.
Absolutely nothing. It prompts me a dialog which says to import a resource. I choose the resource I have made. But in the next dialog, all I see is an empty box, containing nothing that can be imported. This thing is getting weirder and weirder...

What method are you following to import pictures in carbon with interface builder?

gekko513
Feb 20, 2006, 02:46 PM
I've only used Cocoa. I'm just throwing out some ideas just in case I happen to suggest something you haven't tried.

Soulstorm
Feb 20, 2006, 03:14 PM
I've only used Cocoa. I'm just throwing out some ideas just in case I happen to suggest something you haven't tried.
Well I guess that's the price for me to learn C++... Everyone here uses Cocoa and can't help me. In Cocoa i think, there arent such problems, as there are many image formats you can import, such as plain png and jpg files.

Soulstorm
Feb 20, 2006, 03:42 PM
Sorry for the double post. I figured out what's happening. A guy at apple discussion forums told me what I must do. Damn! I would have never figured this out.

Apparently, many people have this question, since this system is much complicated.

Look at this page:

http://www.meandmark.com/xcodetips.html

in there is says:

Using Resources Files with Xcode

I covered this topic indirectly in the book, but using resource files with Xcode and Project Builder has caused problems since Apple released Mac OS X so I decided to place the material here. Resource files were the way to store user interfaces before Mac OS X. They also can store pictures, sounds, and custom data. While nib files have replaced resource files for user interfaces, some programs (mostly Carbon programs) still need to use resource files. Xcode supports resource files, but it makes using them tricky. If you need to use resource files in your program, you must take the following steps:

Give your resource files the extension .r or .rsrc.
Add a Build Resource Manager Resources build phase to your target.
Add your resource files to the Build Resource Manager Resources build phase.
When you give resource files the extension .r or .rsrc, Xcode compiles the resource files in your project, merges them into one resource file, and automatically opens the file when your program launches. If you use a different file extension, you must write code to open the resource file so you can load the file's resources.

The Build Resource Manager Resources build phase compiles the resource files in your project. Unfortunately, none of Xcode's project templates includes this build phase so you must add the Build Resource Manager Resources build phase to your targets. Choose Project > New Build Phase > New Build Resource Manager Resources Build Phase.

When you add a resource file to your project, Xcode adds the file to the Copy Bundle Resources build phase. The Copy Bundle Resources build phases just copies the files to the Resources directory in the application bundle. You must move your resource files to the Build Resource Manager Resources build phase.

Click the disclosure triangle next to a target in the Groups and Files list to see the target's build phases. Click the disclosure triangle next to a build phase to see the files in the build phase. Select a file and drag it to move the file to a different build phase.