0 Replies - 2856 Views - Last Post: 05 September 2012 - 04:09 AM

#1 scourgy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-September 12

Can't read data from plist.

Posted 05 September 2012 - 04:09 AM

Hello, friends. I am new here, so I will introduce myself. My name is Plamen and I am from Bulgaria. I need some help about my quiz application. I can't read 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 where is my mistake:


#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;



#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];


Here's my plist:

Posted Image

P.S: Sorry for my bad english.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1