Литой объект в вызове с ProfileSelectorOnMaintHaineHead iOS

StackOverflow https://stackoverflow.com/questions/9504298

  •  14-11-2019
  •  | 
  •  

Вопрос

Если я использую

[self performSelectorOnMainThread:@selector(uploadDidEnd:) withObject:foo
        waitUntilDone:YES]
.

в методе - (пустота) Uploaddidend: (ID) отправитель

Какой объект отправляется?В звонке Foo является пользовательским классом?Как я могу преобразовать этот отправитель в мой объект?

Я пытаюсь бросить, но у меня есть

'-[_NSThreadPerformInfo CountY]: unrecognized selector sent to instance 0x52bbd0'
.

В Уведомлениях я использую отливку от отправителя на Nsnotification и уведомление имеют свойство объекта, но для NSTHAED я не нашел.

спасибо.

Это было полезно?

Решение

You can think of:

[self performSelectorOnMainThread:@selector(uploadDidEnd:)
      withObject:foo
      waitUntilDone:YES]

as sort of the same as:

[self uploadDidEnd:foo];

Are you sure that's what you're trying to do?

If so: inside your uploadDidEnd: implementation, you can cast foo to whatever object type it really is like so:

- (void)uploadDidEnd:(id)sender
{
  FooClass *foo = (FooClass *)sender;
  [foo doSomething]; // or whatever
}

Другие советы

  1. The argument declared a sender is the only parameter passed to your method. performSelectorOnMainThread:withObject:waitUntilDone: passes its argument after withObject to the selector to be performed, so yes, here foo will be passed to uploadDidEnd:

  2. Casting is not a solution. Objective-C is a dynamic language, so even if casting eliminates compiler warnings, the actual implementation of the object wouldn't change, so it naturally would not repond to messages.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top