2012-07-26 4 views
0

온라인으로 iOS 예제를 살펴 보았습니다. iOS 앱이 시작될 때 앱이 배열을 초기화 한 다음 객체를 추가하는 앱을 발견했습니다. 내 구현 파일에 (void) viewDidLoad를 사용하지만 그래서 내가 왜 누군가가 말해 줄 수 iOS 앱로드시 객체로 배열 초기화

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

를 사용할 때 배열에 약식 것은 작동하지 않을 때 작품을 초기화? 감사! 여기

는 코드입니다 -

(void) viewDidLoad 
{ 
if (self) { 
    questions = [[NSMutableArray alloc] init]; 
    answers = [[NSMutableArray alloc] init]; 

    // Add objects to the arrays 
    [questions addObject:@"What is 1+1"]; 
    [answers addObject:@"2"]; 

    [questions addObject:@"What is 2+2"]; 
    [answers addObject:@"4"]; 

    [questions addObject:@"What is 3+3"]; 
    [answers addObject:@"6"]; 
} 

[super viewDidLoad]; 

및 initWithNibName

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 

    // Create two arrays and make the pointers point to them 
    questions = [NSMutableArray array]; 
    answers = [NSMutableArray array]; 

    // Add questions and answers to the arrays 
    [questions addObject:@"From what is cognac made?"]; 
    [answers addObject:@"Grapes"]; 

    [questions addObject:@"What is 7 + 7?"]; 
    [answers addObject:@"14"]; 

    [questions addObject:@"What is the capital of Vermont?"]; 
    [answers addObject:@"Montpelier"]; 

} 
return self; 
} 
+0

initWithNibName : bundle :이 호출되는지 여부를 알고 있습니까? 스토리 보드 사용 여부와 같이 앱의 구조에 따라 다를 수도 있고 그렇지 않을 수도 있습니다. 거기에 성명서를 써서보세요. – rdelmar

+0

그것은 호출되지 않습니다. 나는 NSLog를 사용하여 검사했다. 그리고 네, 스토리 보드를 사용하고 있습니다. initWithNibName을 작동시키기 위해 뭔가 다른 점이 있습니까? – wackytacky99

답변

0

난 당신이 스토리 보드를 사용하는 경우, initWithCoder 대신 initWithNibName의라고 생각하는 코드 : 넣어 :, 그래서 묶고 대신에 배열 초기화.

+0

viewDiDLoad를 사용할 수 있습니까? 그게 좋습니다? – wackytacky99

+0

물론, 여기에 넣을 수 있습니다. 나는 그것이 정말로 중요하다고 생각하지 않는다. – rdelmar

+0

완벽! 감사. – wackytacky99