Вызовите один метод с более чем одним параметром из NSThread - PullRequest
3 голосов
/ 04 июля 2011

Как я могу вызвать один метод из NSThread?

Я могу вызвать один метод, как показано ниже:

[regionsMapView addAnnotation:addAnnotation];

Как я могу вызвать его в NSThread?Я использовал, как показано ниже:

[NSThread detachNewThreadSelector:@selector(addAnnotation) 
                         toTarget:regionsMapView 
                       withObject:addAnnotation];

Но приложение падает с журналом, как показано ниже:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSThread initWithTarget:selector:object:]: target does not implement selector (*** -[MKMapView addAnnotation])'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x0182b5a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x0197f313 objc_exception_throw + 44
    2   CoreFoundation                      0x017e3ef8 +[NSException raise:format:arguments:] + 136
    3   CoreFoundation                      0x017e3e6a +[NSException raise:format:] + 58
    4   Foundation                          0x0006c392 -[NSThread initWithTarget:selector:object:] + 146
    5   Foundation                          0x0006c2d3 +[NSThread detachNewThreadSelector:toTarget:withObject:] + 98
    6   MJA                                 0x00008a8e -[TaetPaViewController showAddress:withItem:] + 389
    7   MJA                                 0x00008eb9 -[TaetPaViewController UpdateInfo] + 784
    8   MJA                                 0x0000835a -[TaetPaViewController parseTheLocalXml] + 408
    9   Foundation                          0x0006ccf4 -[NSThread main] + 81
    10  Foundation                          0x0006cc80 __NSThread__main__ + 1387
    11  libSystem.B.dylib                   0x911a47fd _pthread_start + 345
    12  libSystem.B.dylib                   0x911a4682 thread_start + 34
)
terminate called after throwing an instance of 'NSException'
Program received signal:  “SIGABRT”.

1 Ответ

3 голосов
/ 04 июля 2011

Вы забыли двоеточие в конце.

@selector(addAnnotation)

не

@selector(addAnnotation:)

Первый вызывает метод, который не принимает параметров, а второй принимает один параметр. Ваш код должен быть таким

[NSThread detachNewThreadSelector:@selector(addAnnotation:) 
                     toTarget:regionsMapView 
                   withObject:addAnnotation];
...