UIAlertView not showing

I have a little problem with one of my UIAlertViews. I try to show this, complete some tasks, and then automatically fire. This is the code I'm currently using:

callingTaxi = [[UIAlertView alloc] initWithTitle:@"" message:@"検索中" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil]; [callingTaxi show]; /* Do some tasks */ [callingTaxi dismissWithClickedButtonIndex:0 animated:YES]; [callingTaxi release]; 

However, UIAlertView shows only halfway. I see that the background is getting dark, but then, after completing the tasks, a warning appears and disappears again.

Any ideas how to solve this problem?

Ben

0
source share
5 answers

It shows, but you immediately fire it, instead of waiting for the user to do something with

 [callingTaxi dismissWithClickedButtonIndex:0 animated:YES]; 

IOS doesn't have time to fully display it. In any case, this is not as expected, the rejectWithClickedButtonIndex function will be used. What are you trying to achieve here?

Edit: I think you need to assign a delegate to the UIAlertView and let the delegate handle what happens inside the AlertView.

+3
source

You should not close it inside the same function that shows it, closes it with a timer or as a reaction to another event.

+1
source

You do not need a delegate. The problem is that the tasks you are performing must be performed in the background thread, so the main thread is left alone to update the screen.

If you update your code to use blocks and send queues, everything will work:

 callingTaxi = [[UIAlertView alloc] initWithTitle:@"" message:@"検索中" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil]; [callingTaxi show]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, NULL), ^{ /* Do some tasks */ dispatch_async(dispatch_get_main_queue(), ^{ // this code is back on the main thread, where it safe to mess with the GUI [callingTaxi dismissWithClickedButtonIndex:0 animated:YES]; [callingTaxi release]; }); }); 
+1
source

you must create a method for alertview

 - (void) alertView: (UIAlertView *) alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{ // Do stuff // Or if you have multiple buttons, you could use a switch [callingTaxi release]; 

Or you could autorelease ..

But x3ro gave the correct answer, you yourself call the method, and do not expect the user to click the button.

0
source

uialertview fired: [callTaxi rejectWithClickedButtonIndex: 0 animated: YES]; before the user can read it.

How long are you going to read it by the end user ???

0
source

All Articles