4

Can anyone tell me the correct way to check if sender was a UIBarButtonItem or not. NSLog gives me these depending on what sender is:

sender for segue = <UIBarButtonItem: 0x6845e70>

sender for segue = <NSIndexPath 0x687fd00> 2 indexes [0, 0]

What command is used in an if statement to check for UIBarButtonItem?

Thanks

Darren
  • 10,182
  • 20
  • 95
  • 162

3 Answers3

11
if([sender isKindOfClass:[UIBarButtonItem class]])

should do it for ya

Jesse Naugher
  • 9,780
  • 1
  • 41
  • 56
  • 1
    It is worth noting that occasionally `isKindOfClass` can be dangerous - although I doubt this would be of concern here, it's good to know. Apple's definitive example is using it to check if an array is mutable and then finding out later on the object you *thought* could be modified was actually immutable all along. This is covered in the `NSObject` reference: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html – lxt Dec 12 '11 at 17:23
1

Check this awnser: How do I test which class an object is in Objective-C?.

You could log the sender's class.

NSLog(@"Sender is a %@",NSStringFromClass([sender class]));
Community
  • 1
  • 1
thijsai
  • 1,795
  • 1
  • 18
  • 26
0

Worked for me !

if([sender isKindOfClass:[UIBarButtonItem class]])
{
    //Do stuff here
}
Edwin O.
  • 4,998
  • 41
  • 44