Class transfer method as a selector problem

I want to create a selector from a class method.

I do like this:

NavigationTreeActionHandler* handler=[NavigationTreeActionHandler self];
NavigationTreeNode* bombsNode=new NavigationTreeNode("Bombs","bigbomb.tif"
     ,handler,@selector(BigBombButtonPressed:));

I need to pass the target and selector to the target method in the NavigationTreeNode. I am trying to get the target using the self property of a class object (I don't know if htis is the right way to do this). Then I get a selector for the class method that I want to call in the class.

Everything compiles fine, but when using:

[[handler class] instanceMethodSignatureForSelector:selector];

I get zero and don't know why ... can anyone help?

+3
source share
2 answers

A few suggestions:

  • [NavigationTreeActionHandler self]will work just fine to get the class object, but I would declare it handleras a type idinstead NavigationTreeActionHandler*, because it is not a reference to an instance of the type

  • [handler class] ; handler .

  • instanceMethodSignatureForSelector: nil, handler selector. .. NSLog, , :

    NSLog ( " =% @sel =% @", , NSStringFromSelector ());

, instanceMethodSignatureForSelector: . , [handler performSelector:selector]; , ?

+3

, , , class , , [[handler class] instanceMethodSignatureForSelector:selector] handler. , - class , +class -class +class , , - ().

, , , , :

[handler methodSignatureForSelector:selector]

, , .

+1

Source: https://habr.com/ru/post/1746853/


All Articles