Search code examples
objective-cselectorunrecognized-selectorperformselector

Unrecognized selector error with performSelector: method


I call

[delegate addText:button.titleLabel.text withSelector:@selector(addElement:) fromKeyboard:self.name]

which corresponds to

- (void)addText:(NSString *)text withSelector:(SEL)selectorName fromKeyboard:(NSString *)name {

   [tempData performSelector:@selector(selectorName) withObject:text];

}

However, when I call the perform selector method on tempData, I get the error. When I replace selectorName with (addElement:) it works fine.


Solution

  • You only write like that

    [tempData performSelector:selectorName withObject:text];
    

    it is already a selector so you dont need to write @selectr(...)