No delegate in HeaderView.xib


#1

Normally, when you create a view controller and view using an xib file, the .h, .m and .xib files have the same file name. When you are making the connections in Interface Builder, an object (a UIButton say) can make the file’s owner (usually a view controller) its delegate. This is not the case with HeaderView.xib The delegate “option” is not available for the UIButtons. In this situation, in Interface Builder you set the class of the file’s owner to ItemsViewController. So, the file names are not the same: ItemsViewController and HeaderView.

Is that the reason you cannot assign a delegate to the UIButtons in Interface Builder? In other words does Interface Builder “know” when the xib is associated with .h and .m files by having the same file name and so provides the ability for objects to assign delegates? And, when Interface Builder “sees” that the name of the xib file is not the same as the file’s owner, it does not provide the delegate assigning capability?


#2

[quote=“gtmcge”]The delegate “option” is not available for the UIButtons. In this situation, in Interface Builder you set the class of the file’s owner to ItemsViewController. So, the file names are not the same: ItemsViewController and HeaderView.

Is that the reason you cannot assign a delegate to the UIButtons in Interface Builder?[/quote]
A UIButton works on target/action - it does not have a delegate property.

Buttons are dumb, you don’t need to assign a ViewController as a delegate for a button, since it’s just a button. The information it provides is limited to whether it’s touched or not.

Buttons should be connected to an -(IBAction) method in the ViewController that does something when the button is pressed. This is target/action, not delegation.

Also, the name of the XIB isn’t important, so long as you assign it to the correct File’s Owner (ViewController) in the Identity inspector. The default - where they’re all the same name and automatically connected by XCode - is just a convenience. If you connect the File’s Owner to your ViewController and implement initWithNib you can use whatever name you want.


#3

Thanks much, for the reply.