Wiring NSToolBarItem with XIBs - objective-c

For some reason I'm having a very difficult time wiring my NSToolbarItem to an IBAction.
I'm using an NSWindowController with its own XIB. The NSToolbar is dropped into the XIB, and I added the NSToolbarItem without issue. This whole NSWindowController is created by a master NSViewController when an image is clicked.
The problem lies with the new button not sending. I unchecked "Autovalidates" and checked "Selectable" so that I could actually click the button.
However when pressed, I receive "unrecognized selector sent to instance".
I've wired this several times over through the XIB interface to make sure I wasn't messing up.
What's going on? Thank you.
Full error:
-[__NSCFType buttonPressed:]: unrecognized selector sent to instance 0x101915010

The delegate class does not know the selector you've wired. Either your delegate is wrong or you've got a typing error in your method.
Check the signature of the Method you've declared in your headerfile vs. its implementation in the class file. Perhaps you forgot to declare a parameter.
edit:
the class type where the selector is called looked weird, so I googled __nscftype unrecognized selector. here are some suggestions, it seems like your delegate is already disposed :
http://imlocation.wordpress.com/2007/09/13/strange-objects-nscftype-indicate-memory-management-bugs/
[__NSCFType searchKeyword:]: unrecognized selector sent to instance 0x6d8eb80

Related

File's owner thinking it is superclass

Something very strange is going on with my interface builder. So I created an NSWindowController subclass in Xcode, with the create XIB option enabled. I started coding, and I successfully connected to file's owner.
But, when I run my app, I get the error :
Failed to connect (workspaceControl) outlet from (NSWindowController) to (NSSegmentedControl): missing setter or instance variable
Failed to connect (workspaceField) outlet from (NSWindowController) to (NSTextField): missing setter or instance variable
Could not connect action, target class NSWindowController does not respond to -changeNumberOfWorkspaces:
I don't know why this error is showing up as I have my code set up right:
And the File's owner is set to the right class (AddController):
So why does it try to connect my views to NSWindowController instead of my subclass?
EDIT:
Where I actually use the AddController in code:
AppDelegate.h
AppDelegate.m
It's in appdelegate because it is a menubar app. (In case anyone was wondering)
Because the actual object that is instantiated in your running program is an NSWindowController, not an AddController. You've shown us that AddController is properly declared, and you've shown us that your nib's File's Owner is set to AddController; that's great, and is why you don't get a compile-time warning or error about things being wired up incorrectly. But you haven't shown us where the controller object actually gets instantiated; and examining that would presumably reveal that it hasn't been changed to AddController. So at runtime you've got an NSWindowController, in violation of what you promised to IB would be the case; and so you get runtime errors.

Unrecognized Selector Sent to Instance; selector doesn't exist?

So I'm new to objective c, practically new to programming in general.
Anyway, in my simple program, I control-dragged my UITextField from the storyboard into my ViewController.m thinking it was a way to create a method to be invoked when the field was entered/tapped on. It wasn't long until I deleted the method.
When running the simulator, the keyboard would come up and the text field would already be focused on. If I tapped anywhere else on the screen, it resulted in a crash giving me the unrecognized selector error for the selector I already deleted.
There's nothing in my ViewController.h and the rest of the code seems fine. If I re-add the selector with no instructions, it behaves as intended and the keyboard resigns. My question is, why am I getting this error?
It would be more helpful to have the output of the crash. With that said I suspect your storyboard still has an outlet hooked up, referencing the function or outlet you created. From your storyboard click on your textfield and then navigate to the connections inspector (view -> utilities -> connections inspector). From there you should be able to see any connections you have made. Click the x to get rid of it.
The connection inspector is the icon in the upper right with the right facing arrow inside of a circle.
Edit:
I realized you asked why this is happening and not how to fix it. Unrecognized selector means just what it sounds like. Your code, in this case the storyboard is trying to call a method or access a variable on an object that doesn't implement that method. Normally the compiler catches these types of errors in your code but there are cases it can't catch, like the one your experiencing. For example it is ok to assign an NSArray object to a variable declared as something else, say an NSString as follows
id object = #[#"hello", #"world"];
NSString *notAString = object;
[notAString length];
Try running this and it will crash with a similar error because NSArray implement the length method, or in Objective-c speak, it doesn't respond to the selector "length".
Most typically it's this:
Select your UITextField in IB, go to the Connections inspector and remove the ghost connection to the removed method.

NSButton argument binding doesn't pass argument?

I have a NSCollectionView with a NSButton in the collection view item. The xib's owner is set to my BatchListViewController and the controller has the method
#interface BatchListViewController : NSViewController
-(IBAction)another_click;
#end
I set the binding for target to be:
This works fine but I also want to send the underlying model to the another_click method. According to the Apple docs,
The objects specified in the argument bindings are passed as parameters to the selector specified in the target binding when the NSButton is clicked.
So I set the binding for argument to be:
This runs fine if I keep the selector method's signature the same another_click: but if I change it to
-(IBAction)another_click:(id)arg;
I get the dreaded error:
BatchListViewController another_click]: unrecognized selector sent to instance
What am I doing wrong? Apple's docs say this is possible but I haven't been able to find an example of this working. Even other SO threads are saying this isn't possible but that can't be right.
The colon is part of the method signature, and you've forgotten to include it when setting up your bindings.

Creating member object in Xcode: Program received signal: "SIGABRT"

Warning: complete newbie Xcode question.
In MainViewController.h I have the following line:
IBOutlet WorkItem *m_WIone;
I have created a class called WorkItem which is inherited from UILabel. The line above is so that I can use m_WIone (which will eventually become an array of such objects) as a member variable throughout MainViewController.
I have tried various ways to call WorkItem methods and finally settled on:
[m_WIone Reset];
where Reset is a WorkItem method. The method is declared in WorkItem.h as:
-(void) Reset;
and in WorkItem.m as:
-(void) Reset {}
With or without contents in this method, the app always crashes with:
Thread 1: Program received signal: "SIGABRT".
In the logging, I read:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel Reset]: unrecognized selector sent to instance 0x6a5f9f0'
How can I solve this? Am I even declaring this member variable correctly? (Despite trawling through StackOverflow, I cannot find the solution.)
Did you specify your custom class for the NIB? It seems like you want a widget in XCode's Interface Builder to use your custom class. Only the default class (UILabel) would be instantiated instead of your custom class.
Click on the UILabel you're using as the outlet and change the class (the screenshot here is for UITableView, but it should work the same for UILabel).
With that being said, there are alternatives to what you're trying to do. Instead of just using UILabel (which you eventually plan to make an array of them). Why not use a UITableView and customize cells to what you see fit (since UITableViews optimal for displaying lists of items)?

Accessing NSImageView giving EXC_BAD_ACCESS

I've got a strange problem here.
I have a class that I'll call MainView. In MainView I have one NSImageView, which I'll call imageView. I've hooked this up to an image view through Interface Builder. I've also initialized an instance of MainView in Interface Builder, and have connected an outlet to that instance to another class with an ivar name of mainView. So then, I access the image view like this:
[mainView imageView]
So then, for a test I NSLog'd the imageView and it returned the address of the objet. So far so good.
Here's the problem: now I'm trying to get the origin of that imageView by doing this:
NSPoint point = [[mainView imageView] frame].origin;
This should work, right? I'm getting an EXC_BAD_ACCESS (also got a SIGABRT once) warning here with the error in console of: -[NSImage frame]: unrecognized selector sent to instance 0x1001d5fd0
The strange part is that this always used work just fine, but I changed some ivar names and it seemed to mess up the whole thing. I almost know for certain it's not a hookup issue with IB because I get a memory address when I log the object. Any ideas?
The error message
-[NSImage frame]: unrecognized selector sent to instance 0x1001d5fd0
means that imageView is pointing to an NSImage object instead of an NSImageView object. It looks like somewhere in your code you’re reassigning the imageView outlet, making it point to an NSImage instance.