2010-06-11 3 views
0

특정 시간 집중 코드가 실행되기 전에 하위 뷰를로드해야하는 명령이 있습니다. 그러나 명령이 실행되면 적시에 코드가 실행되고 하위보기가 표시됩니다. 이 문제를 해결하기 위해 할 수있는 일이 있습니까?코드 실행 전에 ipad subview가로드되지 않음

progressViewController = [[ProgressView alloc] initWithNibName:@"ProgressView" bundle:[NSBundle mainBundle]]; 
[self.view addSubview:[progressViewController view]]; 



NSString *[email protected]"guy"; 
NSString *encodedName =[[NSString alloc] init]; 

int asci; 

for(int i=0; i < [name length]; i++) 
{ 
    //NSLog(@"1"); 
     asci = [name characterAtIndex:i]; 
    NSString *str = [NSString stringWithFormat:@"%d,", asci]; 
     encodedName =[encodedName stringByAppendingFormat: str]; 
} 

NSString *urlString = [NSString stringWithFormat:@"someurl.com"]; 

NSURL *theUrl = [[NSURL alloc] initWithString:urlString]; 

NSString *result=[NSString stringWithContentsOfURL:theUrl]; 

result = [result substringFromIndex:61]; 
result = [result substringToIndex:[result length] - 20]; 

NSLog(result); 


outLab.text=result; 


[[progressViewController view] removeFromSuperview]; 

답변

0

1) 당신은 할 수

- (void) f 
{ 
// executed in main UI thread 
progressViewController = [[ProgressView alloc] initWithNibName:@"ProgressView" bundle:[NSBundle mainBundle]]; 
[self.view addSubview:[progressViewController view]]; 

    [NSThread detachNewThreadSelector:@selector(doCompute) toTarget:self 
     withObject:nil]; 

} 

- (void) doCompute 
{ 
// in a different thread....so we need a autoreleasepool 
    NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; 
    // do your computation here... 

[self performSelectorOnMainThread:@selector(taskComplete:) 
           withObject:result waitUntilDone:NO]; 

[autoreleasepool release]; 

} 

- (void) taskComplete 
{ 
    // executed in UI thread 
    [self.progressView removeFromSuperView]; 
} 
0

.... 하위 뷰

2) 시도 분할 다른 스레드에 집중적으로 시간을 추가 한 후 을 [self.view의 setNeedsUpdating]을 시도 뷰를 서브 클래 싱 한 다음 viewDidLoad 함수를 사용하여 장기 실행 코드를 실행하십시오.