question about event loop

Discussion in 'iOS Programming' started by Howiieque, Feb 5, 2010.

  1. Howiieque macrumors regular

    Joined:
    Feb 1, 2009
    #1
    Code:
    - (IBAction)test:(id)sender {
    	UIView *anotherView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    	anotherView.backgroundColor=[UIColor whiteColor];
    	[self.view addSubview:anotherView];
    	[self performSelectorOnMainThread:@selector(viewTest) withObject:nil waitUntilDone:YES];
    	NSLog(@"%@", self.view.subviews);
    	for (long long i=0; i<1000000000; i++) {
    		;
    	}
    	[anotherView removeFromSuperview];
    	[anotherView release];
    }
    
    
    - (void)viewTest {
    	UIView *second=[[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)] autorelease];
    	second.backgroundColor=[UIColor blackColor];
    	[self.view addSubview:second];
    }
    hi. everyone.
    here is the code i added to the view controller. a button will trigger the test: method. after clicking the button, the button seems to be blocked for several seconds. meanwhile another does not show up. when the button becomes normal, the second(view) shows up.

    i think that the anotherView is actually added to the view hierarchy,which can be tell by the output, but not until the next cycle, will it redisplay. so does the second(view). am i right.
    if i change the waitUntilDone to NO, the second(view) will actually added to the view hierarchy till the next cycle. right?

    i am not familiar with the event loop. please give some comment.
     
  2. Howiieque thread starter macrumors regular

    Joined:
    Feb 1, 2009
    #2
    i make a subview of UIView to response to tap. simply output text.
    the anotherView fails to response.
    while the second(view) does. can someone explain the reason?
     

Share This Page