// Original //
I want to call this guy
-(void)addFavorite:(NSString *)favoriteToAdd
at, @selector here
action:@selector([addFavorite favoriteToAdd:@"string"])];
But I keep getting syntax error no matter which way I write it.
Can someone point out the appropriate way to call this function? When it had no parameter and was “addFavorite,” it worked fine.
// Update //
I apologize for not being more specific. This is an iphone application. I have a view with a button, when the button is pressed, an NSString is grabbed and passed to addFavorite (function above). I get syntax errors when attempting to add a parameter to addFavorite.
I want to call the following addFavorite
-(void)addFavorite:(NSString *)favoriteToAdd
Something like this
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector([addFavorite: favoriteToAdd:@"testString"])];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
error: Expected ‘:’ before ‘[‘ token
[obj action:@selector(addFavorite:) withObject:@"string"]Edit: can’t spell today 🙂
One of the methods for calling selector on button click:
You’ll then have to PULL the string in
addFavoriteClickfrom where it’s defined and pass it intoaddFavorite: