Objeto de reparto en una llamada con el PresentistectoronMainthread iOS
-
14-11-2019 - |
Pregunta
si yo uso
[self performSelectorOnMainThread:@selector(uploadDidEnd:) withObject:foo
waitUntilDone:YES]
En el método - (VOID) UPLOADDIDENDEND: (ID) SENDER
¿Qué objeto es el remitente?¿En la llamada Foo es una clase personalizada?¿Cómo puedo convertir este remitente en mi objeto?
Estoy tratando de lanzar pero estoy teniendo
'-[_NSThreadPerformInfo CountY]: unrecognized selector sent to instance 0x52bbd0'
En las notificaciones, utilizo un elenco del remitente a la nsnotificación y la notificación tiene la propiedad del objeto, pero para Nsthread no encontré.
gracias.
Solución
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
}
Otros consejos
The argument declared a
sender
is the only parameter passed to your method. performSelectorOnMainThread:withObject:waitUntilDone: passes its argument afterwithObject
to the selector to be performed, so yes, herefoo
will be passed to uploadDidEnd: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.