tags:

views:

101

answers:

1

// 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

+4  A: 

[obj action:@selector(addFavorite:) withObject:@"string"]

Edit: can't spell today :)

One of the methods for calling selector on button click:

[buttonObj target:self action:@selector(addFavoriteClick)]`

You'll then have to PULL the string in addFavoriteClick from where it's defined and pass it into addFavorite:

Matt S
I'm sorry but I don't understand how this works. I want to add "favoriteToAdd," and I do not have an "obj." The @selector is an action when a button is clicked.
Oh Danny Boy
Do you want it to perform 'addFavorite' when you click a button?
Matt S
Yes, and I want to pass addFavorite a String. I am searching for the objective-c/iphone equivalent of onClick{ addFavorite(myString); }
Oh Danny Boy
What kind of button are you clicking? Where is the string you want to pass to `addFavorite:` being defined?
Matt S
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addFavorite:)]; self.navigationItem.rightBarButtonItem = addButton; [addButton release];I want to use a test string for now of @"test" but eventually I will grab the string from a title on the view. My addFavorite works. I just need to call it and pass an NSString param.
Oh Danny Boy
Is your problem that when you click on the button nothing happens? You call it by pressing the button, or are you wanting to include an argument or other state with the call and that is messing you up?
Ukko
Ukko, I posted above as to provide formatting for the code.
Oh Danny Boy