I have really simple example, but I can’t understand how I could get information about the method that call selector inside it. For example:
-(void)methodOne {
[self performSelector:@selector(methodTwo:)];
}
-(void)methodTwo:(id)sender {
//How to know which method performed selector???
}
I think this example is pretty simple, I just need to understand this, again, the question is, how could I know from methodTwo: which method perform selector, so from which method I called methodTwo:.
Thanks in advance!
If you do want to know which method calls your
methodTwo, you can look at call stack. Look at this …… and the log output (simplified) is …
…
callStackSymbolsreturnsNSArraywith call stack symbols, so, you can look at index 1 to get method which did you call your method. As you can see, there’sNSObject‘sperformSelectorand it’s because you calledmethodTwoviaperformSelector. If you change yourmethodOnein this way …… the output is …
… that’s it. Your question is answered, but I dunno why do you want this. You probably don’t want to know which method exactly did call your method, but which object initiated this call chain. An example is button – you can have one method to handle more buttons and there’s
senderargument to distinguish between these buttons as @stavash pointed out.