can't add xib file to target membership - objective-c

I am trying to add a custom window as a .xib file to my existing OSX project. When I added the xib file, I make sure the target is checked in the "Add to targets"
However, when I view the property of the xib file, it shows that it's not part of the desired target group
The target isn't checked
Then I experimentally add the xib files into "Copy Files" in the build phases. Now the xib file's property looks a bit different, the target is checked but grayed out.
Checked but grayed out target group
Now when I try to access the xib file, for example, using
bool suc = [[NSBundle mainBundle] loadNibNamed:#"GiphyDialog" owner:nil topLevelObjects:nil];
It always returns false.
Or if I try to load the xib file using a window controller:
[[Windowcontroller alloc ]initWithWindowNibName:#"GiphyDialog"];
NSWindow* win = windowController.window;
Even though the File's owner and the window reference are correctly configured (tested in a brand new project successfully), I always failed to load the window with the message "failed to load window nib file 'GiphyDialog'."
How can I add the xib files correctly to the desired target? It's really strange that with a newly created project, I have no problem adding xib files to the target, but with this project, it simply doesn't work. What am I missing?

Xibs must be added to Copy Bundle Resources, not Copy Files.

So I manage to figure out the problem. In my XCode project there is no Copy Bundle Resources under the Build Phases. But I can add it by clicking the + button on the top-left corner of Build Phases. Adding the xib file to the Copy Bundle Resources then fix my issue.

Related

Cocoa failed to load window nib file when nib is localized

I'm trying to create and show new window in my simple Cocoa application:
myWindow = [[MyWindowController alloc] initWithWindowNibName:#"MyWindow" owner:self];
[myWindow showWindow:self];
It's working well with basic nib file without localization, but as soon as I turn on localization for this specific nib file (using Xcode "localize" option available form file inspector), the application gives me this error when executing the code above:
-[MyWindowController loadWindow]: failed to load window nib file 'AuthWindow'.
Should I change the way I'm initializing my window controller when using localized nibs? It fails only when nib containing a window is localized (with just one language - English), when there is no localization configured - the window is loaded and appears on the screen as it should. I can't find the right answer, I'm new to Cocoa on OSX, but have some experience with CocoaTouch and developing for iOS.
I restarted Xcode and the error went away...
I don't know... but whatever...
initWithWindowNibName: can locate a .nib file in a localization directory such as en.lproj/. The problem is, sometimes Xcode forgets to compile a .xib file (an Interface Builder file in XML format, which you usually play with) into a .nib file, or a binary format - especially when the .xib file is just localized by clicking "Localized..." button.
If you open $build_dir/Your.app/Contents/Resources/$locale.lproj you will find some xibs only copied from the source directory.
Relaunching Xcode will resolve the situation, while I'm not sure what the cause is and why relaunching does the trick.
It's an old question, but I found a different solution than those above. In the nib in question, go to the identity panel and make sure the nib's target membership is checked.
I had an error like this. What solved it for me was to make a backup copy of the xib file, delete it from xcode, restart xcode, then add it back. Go figure...

XCode deployment error: 'NSInvalidArgumentException', Could not find a storyboard named 'MainStoryboard'

Like many of the prior 'MainStoryboard missing in NSBundle' questions, I've got the same prompt but have found no issue with naming and no issue with if the storyboard exists within an area XCode likes.
All the pointers lead to the same file, I've changed my .plist a good 5 times to make it responsive to the same call as found in Build Stages. Now I'm all kinds of tired of this crap because I just want to program, not debug compiler screw ups.
It happened in an instant and now I've been a day and a half without an interface that works. How should I proceed?
I got the following similar error in XCode 4.3.3:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: 'Could not find a storyboard
named 'MainStoryboard'
I fixed it by doing the following:
Make sure your -info.plist has Main story board file based name = MainStoryboard
Right Click on your Story Board file in Xcode and select Delete then References Only
Right Click on your project and select Add Files to [Your Project]
Navigate to the story board file, found in the en.lproj folder in your projects directory and add it
Clean, Recompile and Run and you should find it works.
Got the idea from this SO post: XCode 4.2 MainStoryBoard Not Found
Just as a reference to other first timers like me reading through all the SO questions about missing storyboards:
Don't put ".storyboard" at the end of your file name in your plist file. It should look like this:
Main storyboard file base name: MainStoryBoard
When you create a new *.storyboard file, Xcode (version to date) doesn't automatically add it into your build resources. To fix this you must add the file under "Copy Bundle Resources".
Select the Xcode project icon and navigate to: Targets > Build Phases > Copy Bundle Resources
Click the + button at the bottom to add the storyboard file.
After cleaning my Projekt i have every time this Problem......
My solution is:
move the Main.Storyboard intro trash.
Then "Add Files" select your soryboard, after moving the Main.stpryboard from trash zo your desktop.
and, voila. The Error ist gone.
Considering that there is not too much information about your problem, My best bet would be to go to the package Info, and see if the Main Storyboard is set to whatever your main storyboard is.
As of iOS 9 use just "Main" for storyboard name, worked for me.
Ralph Willgoss's steps didn't work for me. I managed to solve it by copying all the viewcontrollers in the storyboard, deleting it (Move to Trash, not Remove Reference), making a new one (rightclicking the project folder and clicking New File, selecting Storyboard) with the same name as the one I deleted and then pasting the copied contents into it.

rename xib file

I started to create an app using tabbar app template provided in xcode. Then I wanted to change the names of the files: FirstViewController should become YellowViewControler and FirstView.xib should become YellowViewcontroller.xib. Changing the name of the xib wasn't done right. It became red as if it didn't exist in the project. So: how should I change the name of the xib files?
Use the "Refactor" tool of Xcode.
This will manage the renaming of the XIB file, the renaming of the interface & implementation of the source file containing the definition of the ViewController, the renaming of your class declarations/definitions, and any references that are used anywhere in your projects, all of this in one action.
Rename the stuff back to what their original name was (FirstViewController) and then go to the interface file for it (.h) and right click on the class name (FirstViewController) and click refactor. This should make sure everything gets changed correctly.
Source this question
Most likely your viewcontroller name still linked to previous owner therefore open the viewcontroller.xib in source code and find the owner and changed to current name. It will fix the problem right away.

can't find info.plist in xcode 4

So the regular intro: I am a newbie to objective c, searched everywhere and could not find, so please help...
All I want to do is to set my app to get location updates in the background - THAT'S IT. I know that I suppose to add location to UIBackgroundModes in the info.plist file in my project, however I have just NO CLUE where info.plist is.
All I see under my project Build Settings under Packaging is info.plist file (with Release and Debug underneath). No presence of UIBackgroundModes whatsoever.
Any help would be greatly welcome! Thanks!
Hit Cmd-1 to make sure you're on the project navigator tab in the left pane.
Then click the main project table entry (the top one with your project name).
Click the "Info" tab in the main area (not the "Build Settings")
You're now looking at your Info.plist fields. You can right-click and Add Row under Custom iOS Target Properties.
The actual .plist file also exists in your project called ProjectName-Info.plist, probably in the Resources folder of your project.
Search for AppName-Info.plist where AppName is the name of your app.

is this problem resolved? image view with folder reference

Anybody know a workaround for this problem described under:
"When you add the folder as a reference ("blue folder") it adds that folder to your bundle and not just the files in that folder. This means that when you want to reference a file in that folder, you have to reference it by doing foldername/myfile.png (because you have to dive into that folder, instead of just files in the root of the bundle).
I haven't found a way around this, so if you need to reference a file in a folder like that - be it in IB or a method like imageNamed: you need to do foldername/filename otherwise it won't be found."
It works when I create groups instead of folder references though.
Oh and I was wondering, if I add a folder with pictures in it with "Create groups for any added folders" selected, is all the structure going to be lost and everything will be on the root in my app bundle on the phone? Because if I go with the finder in my dev project, I can see that xcode copied my folder with all the pictures in it. But if it's true and no structure is kept, it means that I can't have two images with the same name in different folders in my dev project, correct? and even if all my images are in a folder "images" in my dev project, I still access them directly (foo.png not images/foo.png) in xcode, right?
EDIT
OK after adding the User paths (thanks to #Matthew Frederick) I can now see the filename of my images in the dropdown of IB and they show up on the interface! Problem is, it does not add the folder in the dropdown (I only see filename.png not images/filename.png), so when I compile, it looks for filename.png instead of "images/filename.png", so it does not work. I have to put images/filename.png manually in the IB dropdown, but then the image does not show in IB...
Interface Builder will only look for potential graphics/media in your target's header search paths, so if you want access to anything that's not loose in your project folder you'll need to add those paths.
Fortunately it's easy.
In the Project Navigator click on your project, and then in the main area click on your target.
Click the Build Settings tab and scroll down to the Search Paths section.
In the User Header Search Paths subsection double-click on the area in the Project column (3rd column over) and a small dialog will appear:
Click the + button, then type the path to your added folders, relative to the project's base folder, then click Done. The paths should be specified in the form of /yourPathName.
Poof, now IB can see the graphics inside the folder, and will present them as "folderName/imageName" in it's various dropdown menus and such.
Note: This is also true for .h and .m files and anything else inside a folder inside your project's folder: adding paths tells the compiler other places to look (hence the folders you see in my screenshot, "Human Data Classes" and "Machine Data Classes," where I keep my Core Data class files as created by mogenerator).