Jayyrus
Jayyrus

Reputation: 13051

How to show uiviewcontroller while MBProgressHUD is shown

i'm trying to show MBProgressHUD when a button is clicked and at the end of job show a 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];
}

i retrieve this 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

so i try to call directly [self showSingle] in myTask but error EXC_BAD_ACCESS born on presentModalViewController and retrieving in console this 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

what can i do? can you help me?

Upvotes: 0

Views: 1287

Answers (1)

jonkroll
jonkroll

Reputation: 15722

The selector needs to be a method of the receiving object. In this case showSingle is defined as an instance method of your current class, not UIApplication. So instead of sending the performSelectorOnMainThread: message to your UIApplication, you should send the message to self.

[self performSelectorOnMainThread:@selector(showSingle) 
                       withObject:nil 
                    waitUntilDone:FALSE];

Upvotes: 2

Related Questions