file's owner of xib is not what i expect - interface-builder

i'm using xcode4.
i have a xib window (perhaps copyed by another one, i forgot because i have made it some times ago) named: chooseCharacter.xib
i have the chooseCharacter.h and .m as view controller (i thought)
i have added
-(IBAction)doneButtonClick;
on the chooseCharacter.h but i've not seen it in interface builder actions...
i have added this on HighScoreViewController.h and it now shows up...
however, if i put it on HighScoreViewController.h i must put the implementation in chooseCharacter.m or i get
-[ChooseCharacter doneButtonClick]: unrecognized selector sent to instance 0xcc0d9b0'
seems that the window is binded with a file's owner that is HighScoreViewController.h but search implementation in ChooseCharacter.m!!!
how can i bind the xib to the right file?
thanks

found it.
selecting in interface builder, file's owner and clicking in identity inspector under class was HighScoreViewController, changed to chooseCharacter now it works

Related

Could not connect action to NSViewController

I have a stupid problem with Xcode. Sometimes - and I don't know why, because I always follow the same procedure - if I create an IBAction from the nib file of my NSViewController to the .h-file of this NSViewController, I get the error "Could not connect the action buttonCancelClicked: to target of class NSViewController".
It's crazy, because the File's Owner is set to the .h-file and even if I click the button, the IBAction is called. Only Xcode throws this error.
Is this a bug of Xcode? Can I do something to remove this error?
An NSViewController serves to manage NSViews. Disconnect the button first. Declare the action in (maybe another) class, save, and read the header in IB again and connect it in IB the button. That's how I do it and never had a problem.
Another reason that will generate this message is when the class identifier is not pointing to the correct Project. I had copied a class from one project to another.
My initial class identifier looked as follows:
This generated the console messages as shown in the original question.
I set the class then as follows:
This solved the problem.

XCode 4.6 - Document.xib + MainMenu.xib action from MainMenu shall set outlet in Document.xib

I have a MainMenu which should call an action in an AppController which then should send a message to an outlet of the MainDocument.
When I instantiate an object in Interface Builder in MainMenu.xib this cannot send a message to an outlet in a different xib, as far I understand.
Is there a solution to this?
Most of the default items in the menu are hooked up to that strange "First Responder" placeholder that you see in Interface Builder. Any action message you send to it will get sent through the responder chain which is probably what you want. Read that linked document for more information.
(It's rare that you'd need to hook up an outlet across multiple .xib files.)
If I understand you correctly, you are looking to notify the MainDocument object when you click on a menu item in the MainMenu? If that is the case, one way is to use NSNotification to post the message. You can review the Apple Docs on how to do this here: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Notifications/Introduction/introNotifications.html#//apple_ref/doc/uid/10000043i

setValue:forUndefinedKey:]:

FinalViewWithSending *newView = [[FinalViewWithSending alloc]initWithNibName:#"FinalViewWithSending" bundle:nil];
newView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:newView animated:YES]; //it crashes here with a thread 1 error, SIGABRT error..
It says:
"Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<FinalViewWithSending 0x1bef70> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key loginButton.'"
There is no variable called loginButton so Im not sure why i am getting an error...
Thank you
You are getting the error because there is no property called loginButton. Check your .xib file. There is almost certainly a bad link to a FinalViewWithSending object (likely File's Owner) that specifies loginButton even though it doesn't exist in the class code.
Phillip Mills is correct.
The answer here, for anyone searching, is to edit the storyboard and remove any link to the undefined key specified. You have to edit the storyboard file in an external editor: Right click on the storyboard listing in the hierarchy and then click on "show in finder" or what have you. Open in a text editor, remove said links by searching, save and return to Xcode. No more issue.
This happens when you remove something from the view controller improperly.
Agreeing here - Phillip Mills is correct.
Someone mentioned opening the storyboard up in a text editor - this isn't necessary.
Just click on the storyboard, go to the Connections Inspector. If you've got a problematic outlet, you'll see an exclamation marker next to the outlet. Delete it.
Since this is the first search result for this error, I decided to write an answer for rookies like me.
You are going to get this error if you have Ctrl dragged connections from Buttons which generates code in your ViewController and then you delete just the code without removing the connection.
I got this error because I had accidently added a few buttons as Outlets, when I wanted to add them as Actions. I deleted the code that got generated but the bad connections were still there.
To find and remove them, View->Utilities->Show Connections Inspector
Then click through the different buttons you have and click the x to remove the bad connections.
If you have any localizations, search for bad links in all the storyboards (expand storyboard to find localized storyboards).
This was my situation. I was looking for bad links in one storyboard and they were in the localized one.
You can try the way I used to fix my setValue:forUndefinedKey:]: problem.
I had the same problem:
I had previously made a connection using storyboards from a textfield to a header file. I later decided I wanted to rename my object's connection, unfortunately, I didn't break the connection properly. If this problem was the same as mine, a connection existed to a button previously, and the code in the header was deleted, but the connection was not.
Check the object connections in the view you are segueing to.
You can use associated objects to avoid subclassing. As for the setValue:forKey: and setValue:forUndefinedKey:, take a look in the header file (NSKeyValueCoding.h) for details.
According to your description,
Find newView in your interface builder and right click it,
you will see something like loginButton which is abnormal.
Today I was working and I presented this same error, I used the response of Phillip Mills was correct and I had some labels in one ViewController.xib that were not being assigned links, i have five bad links, once assigned links, everything works perfectly, thanks answer of Phillip Mills.
Go to the connection inspector of your xib of FinalViewWithSending view controller & remove the reference of login button. After that it will run. Try It... :)
Probably, you earlier created the LoginButton, Cmd+Shift+F and find the "LoginButton" and remove the Referencing Outlet and Re-build.
This reply might be late relative to the time the question was asked but I just had this issue and I tried all solution posted here but none worked.
Here is my solution which could help anyone in the future.
Firstly the problem, :I used a custom cell class and made my connections, everything worked fine with my app then, I renamed my custom cell class ran my app but crashed with setValue:forUndefinedKey:] error.
My solution : Clicked .xib file, selected Identity inspector and typed the new named class in Custom Class -> Class tag.
App error resolved.

How can I make my (non-document-based) app respond to openFile:withApplication:?

I have an app, which is a single-window, non-document-based app.
I want to make it respond to NSWorkspace-openFile:withApplication:, but only when the path is to a folder, and also implement the File->Open menu. I'm having trouble tracking down how to do this (without becoming a document-based application).
You have to configure your NSOpenPanel to accept directories:
[myOpenPanel setCanChooseDirectories:YES];
Just check what action the Open menu item is connected to in Interface Builder. If I remember correctly, it would be connected to the "First Responder" object and the method open:. Is that right?
In this case, just implement the open: method in your AppDelegate class. (To understand why the method goes to the delegate, read about "nil-targeted actions" in Hillegass' book, or here: http://www.cocoadev.com/index.pl?NilTargetedAction. The thing to remember is that a control connected to "First Responder" in IB is actually IB's way of denoting that the target is nil.)
Note that you will have to implement the open panel yourself using NSOpenPanel -- see some code for example here: NSOpenPanel setAllowedFileTypes
If this is the same thing as that you're doing in openFile:withApplication:, you will probably want to create a common private method and call that method from both openFile:withApplication: and open:.

Dropping Files onto Dock Icon in Cocoa

How can I drop a file(or select to open it in Finder) of a type specified in the Info.plist onto my dock icon and then calling a method with the full path of the file?
If you've set up your Info.plist's CFBundleDocumentTypes array properly (either 'LSItemContentTypes' or 'CFBundleTypeExtensions'), then you just need to set up an NSApplication delegate and implement the delegate method, application:openFile:.
If you're expecting multiple files to be dropped at once, implement application:openFiles:.
For promised files (NSFilesPromisePboardType/kPasteboardTypeFileURLPromise) see Dropping promised files on to application icon in Dock.
Here's an updated solution for Xcode 5.
In AppDelegate.m
-(BOOL)application:(NSApplication *)sender openFile:(NSString *)filename
{
NSLog(#"%#", filename);
return YES;
}
And in Xcode setup Document Types under Project > Targets > Info:
Check settings in Info.plist in case you have an empty 'Document Content Type UTIs' array which should be filled out properly or else deleted.
Your Info.plist should look something like this:
On current systems you can use a UTI instead of the old-style four-char types (such as fold above). In Xcode's document type editor, make a new type with:
Name: Folder
Identifier: public.folder
public.folder is a subtype of public.directory. public.folder matches directories that appear as such to the user, i.e. not packages like .app wrappers.
Select your application in the target group of the side pane and use get info. Then in the new window select the properties tab to add a new document type. Name it "Folder" for convenience and the OS Types needs to be "fold"; the store type and role you can leave as is.
If you're actually making a document-based app, setting it up to give you the path will have you doing far more work than you need to. Simply use the document-based application template. The document controller will create an instance of the right class for you; you need only write that class.
An application you create this way will handle file drops (by opening them as documents) for free.

Resources