delegates and structs

Andy Lee aglee at mac.com
Wed Jul 23 12:43:36 PDT 2008


On Jul 23, 2008, at 3:26 PM, Izidor Jerebic wrote:
> Typically there are two possible reasons for this:
>
> 1. Your controller is not actually a delegate. Confirm this by doing  
> NSLog( @"is delegate: %s", self == [window delegate]  ? "YES" :  
> "NO") in any controller method that is called, and see if you get  
> YES on the output...

Just make sure you don't do it in an init method, because the nib  
connections may not have been made yet.

I would do it in -awakeFromNib method for either your app controller  
or your window controller, whichever has a reference to the window.   
(I don't have Hillegass in front of me, so I don't know how this  
example is constructed.)  By doing it in -awakeFromNib, you guarantee  
it will be called without you having to set anything else up, and you  
guarantee it will be called *after* all nib connections have been made.

If the NSLog says your controller is not the window's delegate, one  
possible reason is that when you dragged the connection in IB, you  
didn't really drag from the window to the controller, but from  
something *inside* the window to the controller.  There are other  
objects like buttons that can also have delegates, so you may have  
made the wrong connection.

> 2. You have misspelled your delegate method. Check the name, or even  
> better, post the complete method implementation (header is not  
> important) to the email (copy/paste, not retype)...

Good point -- we need to see your *exact* code, so don't trust  
yourself to retype it.

One error I've seen recently is creating an instance of the controller  
in IB when you should be using the controller as the File's Owner.   
Again, I don't know the structure of the app so I can't say if this is  
a possible error here.  We can address this if the above measures  
don't get us anywhere.

--Andy

>



More information about the MacOSX-dev mailing list