It seems it is possible. But, another approach might be to just go with standard controls. The amount of answers is fixed. It might make things quite a bit simpler. I could actually do my database access on the viewDidLoad or whatever it's called. It would be pretty simple, actually.
Well, I'll think about it. The problem is I've gone a certain ways down the road with this approach. Still - I haven't gone *that* far. How would it work? I could create a new View Controller. I could have a button or label or something for the question, 4 more for the answers, and one for the English. It's definitely the way to go. None of this table stuff. I just have to figure out a few things.
Well, let's just see if we can tuck it into the table view for now.
Ok, will it seems ok - not bad really. Needs some fine tuning, that's all.

Ok, well, now, let's make sure we can get the table view to advance before getting into the choose answer logic.
Actually, did I take out the answerMode? Sugar. Where is it getting its data from, again?
Ah, yes with this statement:
[tableView reloadData];
In this method:
- (void) viewWillAppear:(BOOL)animated{
So, if I extract a method for what it's doing, this is the method:
- (void) advance_question: (BOOL) animated {
// won't be animated on the first call
if (animated) {
appState.currentShuffledArrayIndex++;
[appState saveState];
}
currentQuestion = [appState currentQuestion];
// answers = [currentQuestion answerArray];
answers = [currentQuestion getAnswerArray: appState];
int rand = arc4random() % 3; // get a number between 0 and 3
NSLog(@"rand: %d", rand);
NSLog(@"Current Question kanji: %@", [currentQuestion questionTxt]);
NSLog(@"Current Question hiragana: %@", [currentQuestion hiragana]);
appState.slotOfCorrectAnswer = rand;
[answers removeObjectAtIndex: rand];
[answers insertObject:[currentQuestion hiragana] atIndex:rand];
// triggers reload, see veiwDidLoad method
[tableView reloadData];
}
Now, let's see if I can call this method to make it advance. I dont' have a next question button set up yet, but what I can do is just call it if the answer mode is yes and something is selected.
Well - that didn't work. When answerMode was "YES", it tried to call the above and crashed in the main method on a bad access on something.
Well, the debugger shows that I'm still screwing up the answerMode, because that's the statement it's crashing on. So, you know what? I'll just do a counter - if it's even, I'll reload, and if it's odd, I'll go into the correction logic.
- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
cntr++; // counter starts at zero,
if ((cntr % 2) == 0) {
//answerMode = @"NO";
appState.currentShuffledArrayIndex++;
[appState saveState];
// etc.
}
else {
check and highlight correct answer
}
Nice...it's working. Yah!
No comments:
Post a Comment