View Full Version : strange result: alert view in for loop
Howiieque
Sep 9, 2009, 08:04 AM
for (;;) {
UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"I wanna know you" message:currentNode.question delegate:self cancelButtonTitle:@"Skip" otherButtonTitles:currentNode.option1, currentNode.option2, nil];
[alertView show];
[alertView release];
}
it seems that it can get the result i want. this even won't show the alert view at all. can someone explain the reason.
robbieduncan
Sep 9, 2009, 09:33 AM
Is that running on the main thread? If so don't do that. OK, actually don't do that on any thread. Ever.
Showing an alert does not block the current thread or stop execution. That is looping as fast as the CPU can creating and asking for alerts to show. You'll run out of RAM and the app will crash (eventually). You need to allow the current iteration of the run loop to end for the alert to show.
Create the alert, show it and use the delegate callbacks...
Howiieque
Sep 9, 2009, 11:38 AM
thank you for your reply. your answer really makes sense.
i still have something can't understand. it is said that everything is blocked when modal view appears.
i upload my test codes. it seems that when i press any of the button, it will result in EXC_BAD_ACCESS. can you tell me a little more about that?
robbieduncan
Sep 9, 2009, 11:53 AM
thank you for your reply. your answer really makes sense.
i still have something can't understand. it is said that everything is blocked when modal view appears.
i upload my test codes. it seems that when i press any of the button, it will result in EXC_BAD_ACCESS. can you tell me a little more about that?
Where? The documentation (http://developer.apple.com/iphone/library/documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html#//apple_ref/occ/instm/UIAlertView/show) for show just says it shows it. It also says if you are using custom buttons you MUST supply a delegate. Which you are not.
Howiieque
Sep 11, 2009, 01:46 AM
:) Really thank you to point out my mistakes.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.