Короче говоря, да, это возможно.
Сначала вы хотите отслеживать вопрос о том, что ваш пользователь в данный момент включен. Вы можете сделать это, сохранив индекс в переменной экземпляра или, если вы планируете разрешить пользователю открывать приложение и начинать с того места, где они остановились, вы можете использовать NSUserDefaults, который записывает на диск и будет сохраняться.
// In the interface of your .m file
int questionIndex;
// In viewDidLoad of your controller, however this will start for index 0, the beginning of your questions array
questionIndex = 0
Сохраняя индекс в NSUserDefaults, вы можете захватить его в ViewDidLoad, и начать, где пользователь последний раз остановились:
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:questionIndex] forKey:@"questionIndex"];
Чтобы сохранить свой ответ, вы можете добавить метод для вашего кнопки называемых answerTapped :,
- (void)answerTapped:(UIButton *)answerButton
{
// Grab the answer from the text within the label of the button
// NOTE: This assume your button text is the answer that you want saved
NSString *answer = answerButton.titleLabel.text;
// You can use your questionIndex, to store which question this answer was for and you can then take the answer and store it in sqlite or where you prefer...
}
Вы можете добавить этот метод к кнопкам как так
[answerButton addTarget:self action:@selector(answerTapped:) forControlEvents:UIControlEventTouchUpInside];
Теперь вы можете написать метод для увеличения значения questionIndex, когда нажата кнопка ответа.
- (void)incrementQuestionIndex
{
// Increment index
questionIndex += 1;
// Update and save value in UserDefaults
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:questionIndex] forKey:@"questionIndex"];
}
Затем вы можете вызвать отдельный окончательный метод для обновления метки вопроса.
- (void)updateQuestionLabel
{
// Grab the question using the index (omit this line and go straight to the next if storing the index in an iVar)
questionIndex = [[[NSUserDefaults standardUserDefaults] objectForKey:@"questionIndex"] integerValue];
// Grab the question using the index. Assumes you have a questions array storing your questions from sqlite.
NSString *question = [questions objectAtIndex:questionIndex];
// Update the question UILabel
[questionLabel setText:question];
}
Пожалуйста, напишите, какой у вас код и какая часть не работает. Текущий вопрос слишком открытый. – bearMountain
Я добавлю свой код сегодня вечером, когда вернусь домой, извините за путаницу. –