1

I'm new to iOS planet, and below is my sample code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    UIButton  * _btnSample = [UIButton buttonWithType:UIButtonTypeCustom];

    [_btnSample setFrame: CGRectMake(100, 160, 200, 30)];

    [_btnSample setBackgroundColor:[UIColor redColor]];

    [_btnSample setTitle:@"Click Me" forState:UIControlStateNormal];

    [_btnSample addTarget:self action:@selector(btnClick::)withObjects   forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:_btnSample];

    //[self btnClick:@"12" :@"13"];

}


- (void)btnClick :(NSString *) stringValue1 : (NSString *) stringValue2
{
    NSLog(@"Click ME Button Clicked with a value::%@",stringValue1);
       NSLog(@"Click ME Button Clicked with a value::%@",stringValue2);
}

in the @selector i need to call btnClick fn which has two parameters, how?

Sankar M
  • 4,549
  • 12
  • 37
  • 55
  • 1
    @WojtekSurowka OP wants to pass the parameter in function call, not how to call the method. – Yogesh Suthar Aug 06 '14 at 09:12
  • Not in answer to the question but I recommend you update your method signature to not use the name of one parameter as part of the next. I expect Xcode is giving you a warning. Use: `- (void)btnClickWith:(NSString *)stringValue1 withString:(NSString *)stringValue2` or similar. This is better practice for Objective-C development. – Tim Aug 06 '14 at 09:31
  • You can use the solution provided in this answer regarding UIButton and passing mulitple parameters to its selector: https://stackoverflow.com/a/53779104/5324541 – Lloyd Keijzer Dec 14 '18 at 11:57

1 Answers1

1

Short answer is that you can't. The action method which is called by a control has to conform to one of the following signatures (see Apple reference):

- (void)action
- (void)action:(id)sender
- (void)action:(id)sender forEvent:(UIEvent *)event

and this is because the parameters to the action methods are supplied by the control and are supplied to allow the action method to decide what to do, if necessary.

If you can explain what those parameters mean, as I didn't see from your question, then we can almost certainly come up with a solution to your problem.

Droppy
  • 9,691
  • 1
  • 20
  • 27
  • No i just want to call a fn which has multiple arguments that is it... – Sankar M Aug 06 '14 at 09:47
  • @sankar2.0 As that method is an action method it must conform to one of the signatures listed in my answer. Sounds like you just need to create a *separate* action method which will itself call `btnClick::`. – Droppy Aug 06 '14 at 09:48