It looks like you're new here. If you want to get involved, click one of these buttons!
Here's my plist:THE .H FILE:
#import
@interface SecondViewController : UIViewController {
int mainInt;
IBOutlet UILabel *timer;
NSTimer *randomMain;
//that was for the timer
int currentQuestion;
}
@property (retain, nonatomic) IBOutlet UILabel *timer; //this is for the timer
@property (retain, nonatomic) IBOutlet UILabel *textQuestionTitle;
@property (retain, nonatomic) IBOutlet UIButton *buttonA;
@property (retain, nonatomic) IBOutlet UIButton *buttonB;
@property (retain, nonatomic) IBOutlet UIButton *buttonC;
@property (retain, nonatomic) IBOutlet UIButton *buttonD;
@property (retain, nonatomic) NSArray *questions;
@property (retain, nonatomic) NSString *answer;
-(void)showNextQuestion;
@end
================================================================
THE .M FILE:
#import "SecondViewController.h"
@implementation SecondViewController
@synthesize timer, buttonA, buttonB, buttonC, buttonD, textQuestionTitle;
@synthesize questions = questions_;
@synthesize answer = answer_;
-(void)randomMainVoid {
mainInt -= 1;
timer.text = [NSString stringWithFormat:@"Time left: %d", mainInt];
if (mainInt == 0) {
[randomMain invalidate];
randomMain = nil;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
mainInt = 11;
randomMain = [NSTimer scheduledTimerWithTimeInterval:(1.0/1.0) target:self selector:@selector(randomMainVoid) userInfo:nil repeats:YES];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Questions" ofType:@"plist"];
self.questions = [NSArray arrayWithContentsOfFile:path];
currentQuestion = -1;
[self showNextQuestion];
}
-(void)showNextQuestion {
currentQuestion ++;
if (currentQuestion < [self.questions count]) {
NSDictionary *nextQuestion = [self.questions objectAtIndex:currentQuestion];
self.answer = [nextQuestion objectForKey:@"QuestionAnswer"];
self.textQuestionTitle = [nextQuestion objectForKey:@"QuestionTitle"];
NSString *varA = [nextQuestion objectForKey:@"A"];
[buttonA setTitle: varA forState:UIControlStateNormal];
NSString *varB = [nextQuestion objectForKey:@"B"];
[buttonB setTitle: varB forState:UIControlStateNormal];
NSString *varC = [nextQuestion objectForKey:@"C"];
[buttonC setTitle: varC forState:UIControlStateNormal];
NSString *varD = [nextQuestion objectForKey:@"D"];
[buttonD setTitle: varD forState:UIControlStateNormal];
}
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end

Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeChange this line:
Then to populate your list of remaining questions: And to fetch a question:
if (remainingQuestions.count == 0) The code above fetches questions in random order, removes each question from the list of current questions once it's been fetched, and then repopulates the array after all the questions have been fetched.
Disclaimer: I typed this code into a browser window have not compiled it, much less tested it. It is perfectly likely to contain a few syntax errors, and may even contain minor bugs.
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome