You would have to extend the UIBarButtonItem class.
Here is an example creating RCBarButtonItem class. I've used initWithTitle for ease, I'm sure you could change it...
The UIBarButtonItem Subclass
#import <UIKit/UIKit.h>
@interface RCBarButtonItem : UIBarButtonItem {
id anObject;
}
@property (nonatomic, retain) id anObject;
- (id)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action withObject:(id)obj;
@end
@implementation RCBarButtonItem
@synthesize anObject;
-(void)dealloc {
[anObject release];
[super dealloc];
}
- (id)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action withObject:(id)obj {
if (self = [super initWithTitle:title style:style target:target action:action]) {
self.anObject = obj;
}
return self;
}
@end
Then this could then be implemented like so:
#import "RootViewController.h"
#import "RCBarButtonItem.h"
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
RCBarButtonItem *button = [[RCBarButtonItem alloc] initWithTitle:@"Hello"
style:UIBarButtonItemStylePlain
target:self
action:@selector(doSomething:)
withObject:@"Bye"];
self.navigationItem.rightBarButtonItem = button;
}
- (void)doSomething:(id)sender {
NSLog(@"%@", [(RCBarButtonItem *)sender anObject]);
}