What is the use of Perform Selector in the objective development of C / Iphone

What is the use of performing a selector on a C lens? and could you tell me the difference between the selector selector and the answers?

+3
source share
3 answers

-respondsToSelector: allows you to check if a particular object responds to a specific selector if your application crashes if you still send a message to it.


-performSelector: (withObject :) just calls a specific method, for example

[object performSelector:@selector(retain)];

will be equal

[object retain];

Why do you need this? A convenient example is presented NSArray: it allows the selector to execute all the objects that it contains, for example

[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

will be equal

for (UIView *view in self.subviews)
{
    [view removeFromSuperview];
}

-makeObjectsPerformSelector: .

+5

SoSelector: , , , .

Selector: .

PerformSelector , , , (). ...

- Selector: withObject: afterDelay:// .. - performSelector: withObject: afterDelay: inModes: - SelectorOnMainThread: withObject: waitUntilDone: - SelectorOnMainThread: withObject: waitUntilDone: : - performSelector: onThread: withObject: waitUntilDone: - performSelector: onThread: withObject: waitUntilDone: :

- performSelectorInBackground: withObject:// . , ManinThread (Application) ... .

.

..

, ...

0

performSelector , , .

, @property (assign) id delegate , id - . delegate nil, , , . , :

if ([delegate respondsToSelector:@selector(delegateMethod:)]) {
    [delegate performSelector:@selector(delegateMethod:)
                   withObject:param];
}

, . performSelector:, . .

NSObject:

performSelectorOnMainThread:withObject:waitUntilDone:
performSelectorOnMainThread:withObject:waitUntilDone:modes:
performSelector:onThread:withObject:waitUntilDone:
performSelector:onThread:withObject:waitUntilDone:modes:
performSelectorInBackground:withObject:

:

0
source

All Articles