views:

354

answers:

3

Hey fellas,

I've got a custom view inside of a UIBarButtonItem, set by calling -initWithCustomView.

OK, so the view renders fine, but when I tap it, it doesn't call the method that I set as the UIBarButtonItem's action property.

Oh, and I have verified that my -deselectAll method works fine.

Keep in mind that I am not using Interface Builder and I am sure that the method signature is correct

Here's my code:

 UIImageView *SOCImageView = [[ UIImageView alloc ] initWithImage:[ UIImage imageNamed: @"cancel_wide.png" ] ];
 SOItem.leftBarButtonItem = [[ UIBarButtonItem alloc ] initWithCustomView: SOCImageView ];
 [ SOCImageView release ];
 [ SOItem.leftBarButtonItem setTarget: self ];
 [ SOItem.leftBarButtonItem setAction: @selector( deselectAll ) ];

Thanks a million

A: 

Jacob, everything looks good, however you may not have provided the correct selector.

Can you verify that your action is actually declared

- (void) deselectAll;

and not

- (void) deselectAll:(id)sender;

If it's the latter, you will need to set the action to @selector(deselectAll:). (note the semi-colon to match the method declaration)

Also, void might be IBAction, but that's not relevant to this problem you're having.

ohhorob
@ohhorob, I'm positive about the method signature.
Jacob Relkin
@ohhorob, I'm also not using IB ;)
Jacob Relkin
ohhorob
@ohhorob, This code is within a view controller that is not being released.
Jacob Relkin
how did you confirm `deselectAll` is not being called? By setting a debugger breakpoint, or do you just not see the expected results?
ohhorob
@ohhorob, see my other question re: debugging. I'm logging out every method call in my app :)
Jacob Relkin
I suggest using a breakpoint to be sure. Also you may have inadvertently over-retained the `leftBarButtonItem` (you are using alloc, and the property is `(nonatomic, retain)`.
ohhorob
@ohhorob, `IBAction` is just an alias to `void`.
Jacob Relkin
it sure is. that's why I mentioned that it's not relevant.
ohhorob
A: 

Is your custom view eating touch events or passing them on to parent view?

Alex Reynolds
@Alex, as you can see, my custom view is just a plain ol' `UIImageView`. So, it's not eating any events, no.
Jacob Relkin
+3  A: 

I do not think the target and action of the UIBarButtonItem apply to custom views. Try using a UIButton instead of UIImageView and applying the target and action to the button.

drawnonward
@drawnonward, Thanks so much!
Jacob Relkin