strange result: alert view in for loop

Discussion in 'iOS Programming' started by Howiieque, Sep 9, 2009.

  1. Howiieque macrumors regular

    Joined:
    Feb 1, 2009
    #1
    Code:
    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.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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...
     
  3. Howiieque thread starter macrumors regular

    Joined:
    Feb 1, 2009
    #3
    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?
     

    Attached Files:

  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Where? The documentation 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.
     
  5. Howiieque thread starter macrumors regular

    Joined:
    Feb 1, 2009

Share This Page