Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
713 views
in Technique[技术] by (71.8m points)

iphone - Two targets with separate .xib (image resources with same names)

I have a project with two targets, let's say appA and appB.

Both targets share code of main view controller (appViewController) except the .xib files.

I also have two sets of png's each for one target.

My file/project structure looks like:

*common* (members of both targets):
    appViewController.h
    appViewController.m

*appA* (members of target appA):
    appViewController.xib
    set of png files

*appB* (members of target appB):
    appViewController.xib
    set of png files

PNG's in both sets have the same names but they are placed in separate folders/groups and one group is member of one target and the other of the other target (same with appViewController.xib)

Everything works fine except when i try to edit .xib files in IB - it seemes to get confused and show partly images from one target and partly from the other.

Since .xib's are somewhat complex (>40 images) editing one with partly wrong images is almost impossible - images have to be properly placed on one background image (background image is also different for appA and appB).

The problem exists only at edit-time (in IB). After compilation all the images in both targets are correct.

I found one quick & dirty solution to this. Before i start editing one .xib i remove references to the other set of png's. That way IB shows correct images for the .xib i'm editing. I simply import back all the references (png's of the other target) when i'm done.

I found a similiar question which was not really answered.

I wonder, does anyone have a cleaner solution to this? There has to be a better way to do it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No answers so far...

So let me answer my own question (still hoping for a better answer).

When you want to edit .xib of one target, you remove the references of the other targets' resources (pngs).

Then you quit xcode and open your project again. The pngs will be the right ones (since xcode doesn't hold references to the wrong ones at the moment).

When you're done - reimport deleted references (take care that you check the right 'target membership').

Edit: This seems to be a known issue with IB - XCode. Till they resolve it we'll just have to use workaround mentioned above.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...