Darren
Darren

Reputation: 10398

Check if sender is UIBarButtonItem

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

Upvotes: 4

Views: 4961

Answers (3)

thijsai
thijsai

Reputation: 1785

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]));

Upvotes: 1

Edwin O.
Edwin O.

Reputation: 5276

Worked for me !

if([sender isKindOfClass:[UIBarButtonItem class]])
{
    //Do stuff here
}

Upvotes: 0

Jesse Naugher
Jesse Naugher

Reputation: 9820

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

should do it for ya

Upvotes: 11

Related Questions