Pregunta

Estoy tratando de mostrar MBProgressHud cuando se hace clic en un botón y al final del trabajo muestra un UIViewController

-(IBAction)submitForm:(id)sender{
[self hideKeyboard];
if([self checkUITextField]){
    HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    [self.navigationController.view addSubview:HUD];
    HUD.mode = MBProgressHUDModeIndeterminate;
    HUD.dimBackground = YES;
    HUD.delegate = self;
    HUD.labelText = @"Convalido registrazione";
    [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
}
}


-(void)myTask{
.
.
.
sleep(3);
[HUD hide:YES];
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
HUD.mode = MBProgressHUDModeCustomView;
HUD.labelText = @"Richiesta inviata!";
[HUD show:YES];
sleep(1);
UIApplication* app = [UIApplication sharedApplication];
[app performSelectorOnMainThread:@selector(showSingle) withObject:nil waitUntilDone:FALSE];
}

-(void)showSingle{
SingleViewController *single = [[SingleViewController alloc] initWithNibName:@"SingleViewController" bundle:nil];
[self presentModalViewController:single animated:YES];
[self release];
}

Recupero este error:

ApplicationName[954:11f03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIApplication showSingle]: unrecognized selector sent to instance 0x7b6d8e0'
*** First throw call stack:
(0x1a53052 0x1be4d0a 0x1a54ced 0x19b9f00 0x19b9ce2 0x1a54e72 0x108f9ef 0x1a2797f 0x198ab73 0x198a454 0x1989db4 0x1989ccb 0x3d7c879 0x3d7c93e 0x777a9b 0x226f 0x21e5)
terminate called throwing an exception

Así que trato de llamar directamente [self showSingle] en mytask pero error EXC_BAD_ACCESS nacido en presentModalViewController y recuperando en consola este error

    [1004:1651b] bool _WebTryThreadLock(bool), 0x7bd6160: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
1   WebThreadLock
2   -[UIWebView _webViewCommonInit:]
3   -[UIWebView initWithCoder:]
4   UINibDecoderDecodeObjectForValue
5   -[UINibDecoder decodeObjectForKey:]
6   -[UIRuntimeConnection initWithCoder:]
7   UINibDecoderDecodeObjectForValue
8   UINibDecoderDecodeObjectForValue
9   -[UINibDecoder decodeObjectForKey:]
10  -[UINib instantiateWithOwner:options:]
11  -[UIViewController _loadViewFromNibNamed:bundle:]
12  -[UIViewController loadView]
13  -[UIViewController view]
14  -[UIViewController viewControllerForRotation]
15  -[UIViewController _visibleView]
16  -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]
17  -[UIViewController presentViewController:withTransition:completion:]
18  -[UIViewController presentViewController:animated:completion:]
19  -[UIViewController presentModalViewController:animated:]
20  -[FormViewController showSingle]
21  -[FormViewController myTask]
22  -[NSObject performSelector:withObject:]
23  -[MBProgressHUD launchExecution]
24  -[NSThread main]
25  __NSThread__main__
26  _pthread_start
27  thread_start

¿que puedo hacer? ¿me puedes ayudar?

¿Fue útil?

Solución

los selector debe ser un método del objeto receptor. En este caso showSingle se define como un método de instancia de su actual class, no UIApplication. Entonces, en lugar de enviar el performSelectorOnMainThread: mensaje a tu UIApplication, debe enviar el mensaje a self.

[self performSelectorOnMainThread:@selector(showSingle) 
                       withObject:nil 
                    waitUntilDone:FALSE];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top