views:

13

answers:

0

Dear Developers.

I am trying to load plist data into UILabels in a utility template app that has two views. There is a flip animation that allows switching between the views.

Here is the structure of the plist:

Root...............................(Array)
........Item 0.....................(Dictionary)
.................Question..........(string)  ///Hello////
.................Answer............(string) ///Goodbye//

I have managed to get the Question String to load into the first view (FlashCard1ViewController) using keys(Constants.h), but i am struggling to get the Answer string to load in the second view (FlippedView). Can anyone help with this?

below is the code i am using, if anybody has further questions or requires clarification please let me know and i will do my best to answer.

with thanks

james

FlashCard1ViewController.h

#import <UIKit/UIKit.h>

@interface FlashCard1ViewController : UIViewController {
 NSMutableArray *flashCards;
 IBOutlet UILabel *Label1;
}

@property (nonatomic, retain) NSMutableArray *flashCards;
@property (nonatomic, retain) UILabel *Label1;


- (IBAction)showInfo;

@end

FlashCard1ViewController.m

#import "FlashCard1ViewController.h"
#import "Constants.h"
#import "FlippedView.h"

@implementation FlashCard1ViewController
@synthesize Label1, flashCards;

/////////////////////Code to load the Array into the UIlable////////////////////////////////////////////////
- (void)viewDidLoad {
    [super viewDidLoad];
 NSString *path = [[NSBundle mainBundle] pathForResource:@"DataDetail" ofType:@"plist"]; //Defines path for DATA For ARRAY//
 NSMutableArray* tmpArray = [[NSMutableArray alloc]initWithContentsOfFile:path]; //initialises the contents of the ARRAY with the PLIST"
 self.flashCards = tmpArray; 
 NSDictionary *Question1 = [flashCards objectAtIndex:0];
 Label1.text = [Question1 objectForKey:Question_KEY];
 self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
 [tmpArray release];
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}

- (void)FlippedViewDidFinish:(FlippedView *)controller {

 [self dismissModalViewControllerAnimated:YES];
}


 - (IBAction)showInfo {    

 FlippedView *controller = [[FlippedView alloc] initWithNibName:@"FlippedView" bundle:nil];
 controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
 [self presentModalViewController:controller animated:YES];

 [controller release];
 }

- (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 {
 // Release any retained subviews of the main view.
 // e.g. self.myOutlet = nil;
}
- (void)dealloc {
 [Label1 release];
 [flashCards release];
    [super dealloc];
}
@end

FlippedView.h

#import <UIKit/UIKit.h>


@interface FlippedView : UIViewController {
 NSMutableArray *flashCards; //provides Directory for detail View//
 IBOutlet UILabel *Label2;
}

@property (nonatomic, retain) NSMutableArray *flashCards;
@property (nonatomic, retain) UILabel *Label2;

- (IBAction)done;

@end

FlippedView.M

#import "FlippedView.h"
#import "FlashCard1ViewController.h"
#import "Constants.h"


@implementation FlippedView
@synthesize Label2, flashCards;

- (void)viewDidLoad {
    [super viewDidLoad];
 NSDictionary *Answer1 = [flashCards objectAtIndex:0];
 Label2.text = [Answer1 objectForKey:Answer_KEY];
 self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
}



- (IBAction)done {    

 FlashCard1ViewController *controller = [[FlashCard1ViewController alloc] initWithNibName:@"FlashCard1ViewController" bundle:nil];
 controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
 [self presentModalViewController:controller animated:YES];

 [controller release];
}


- (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 {
 [flashCards release];
 [Label2 release];
    [super dealloc];
}


@end

Constants.h

#define Question_KEY @"Question"
#define Answer_KEY @"Answer"