iPhone SDK Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsMobile ProgrammingiPhone SDK Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 5th, 2012, 06:04 AM
scourgy scourgy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 1 scourgy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 10 sec
Reputation Power: 0
Can't shuffle my plist.

I can't shuffle my questions and answers from a plist. Here's my code - I have 1 label (for the question) and 4 buttons (for the answers), please tell me how to shuffle the plist? I want random questions each time I start the quiz. :-|
Code:
THE .H FILE:

#import <UIKit/UIKit.h>


@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"];
	NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:path];
	self.questions = [tempDict objectForKey:@"Root"];
	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



Here's my plist:
URL

Reply With Quote
Reply

Viewing: Dev Shed ForumsMobile ProgrammingiPhone SDK Development > Problem with plist.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap