Я создаю simle вопрос-ответ iPhone приложение.NSMutableArray не получает инициализацию в методе initWithNibName
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
// Call the init method implemented by the superclass
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Create two arrays and make the pointers point to them
questions = [[NSMutableArray alloc] init];
answers = [[NSMutableArray alloc] init];
// Add questions and answers to the arrays
[questions addObject:@"What is 7 + 7?"];
[answers addObject:@"14"];
[questions addObject:@"What is the capital of Vermont?"];
[answers addObject:@"Montpelier"];
[questions addObject:@"From what is cognac made?"];
[answers addObject:@"Grapes"];
}
массивов на вопросы & ответов не наполняясь и показывать ноль. В чем может быть проблема?
массив Метод доступа:
- (IBAction)showQuestion:(id)sender
{
// Step to the next question
currentQuestionIndex++;
// Am I past the last question?
if (currentQuestionIndex == [questions count]) {
// Go back to the first question
currentQuestionIndex = 0;
}
// Get the string at that index in the questions array
NSString *question = [questions objectAtIndex:currentQuestionIndex]; **<<- question is nil**
[questionField setText:question];
// Clear the answer field
[answerField setText:@"???"];
}
Где вы храните ваши вопросы и ответы в массивах? Не могли бы вы вставить код, который вы используете для этого? – Tim
в заголовочном файле: '@interface QuizViewController: UIViewController {int currentQuestionIndex; // Объекты модели NSMutableArray *; NSMutableArray * ответы; // Объекты представления - не беспокойтесь о IBOutlet - // мы поговорим об этом вскоре IBOutlet UILabel * questionField; IBOutlet UILabel * replyField; } ' – ExploringApple
попытайтесь установить точку останова в методе -initWithNibName. Посмотри, добирается ли он туда. Я предполагаю, что вы не инициализируете ViewController этим методом, может быть, просто с помощью -init. –