온라인으로 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;
}
initWithNibName : bundle :이 호출되는지 여부를 알고 있습니까? 스토리 보드 사용 여부와 같이 앱의 구조에 따라 다를 수도 있고 그렇지 않을 수도 있습니다. 거기에 성명서를 써서보세요. – rdelmar
그것은 호출되지 않습니다. 나는 NSLog를 사용하여 검사했다. 그리고 네, 스토리 보드를 사용하고 있습니다. initWithNibName을 작동시키기 위해 뭔가 다른 점이 있습니까? – wackytacky99