我一直在線瀏覽一些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 2012-07-26 05:17:56
它沒有被調用。我檢查使用NSLog。是的,我正在使用Storyboard。我應該在這裏做一些改變,使initWithNibName工作? – wackytacky99 2012-07-26 05:19:22