0

I have a trigger to catch the button click on my controller like this

[saveButton addTarget:self action:@selector(save:) forControlEvents:UIControlEventTouchUpInside]; and the relevant function is

- (void)save:(id)sender {
     //implementation code
}

How do call this function in another function, I try to call this function like as follow but it showing error.

(void)checkStatus{
    if(somecondition){
      [self save];
    }
}

Note that I am new to iOS and Objective-C and I am editing a code of another developer. Please give me a solution.

nifCody
  • 2,394
  • 3
  • 34
  • 54
  • 3
    Possible duplicate of [What's the best way to call an IBAction from with-in the code?](http://stackoverflow.com/questions/2889408/whats-the-best-way-to-call-an-ibaction-from-with-in-the-code) – Anand Suthar Apr 25 '17 at 11:52
  • It just gives you an error because your save method needs an parameter. Anbu's Answer is correct. – Retterdesdialogs Apr 25 '17 at 11:54
  • Below answer one way to get answer. You can do it another way also. Put the button action code in another method. While click the button call that method. Next call the same method in your if condition also. – phani Apr 25 '17 at 12:02

1 Answers1

2

your button action has a parameter , so you need to append in the parameter as nil or self.do like

- (void)checkStatus{
if(somecondition){
  [self save:nil];
}
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143