2

2つのビューを持つユーティリティテンプレートアプリのUILabelsにplistデータを読み込もうとしています。ビューを切り替えることができるフリップアニメーションがあります。

plistの構造は次のとおりです。

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

キー(Constants.h)を使用して最初のビュー(FlashCard1ViewController)に質問文字列をロードすることができましたが、2番目のビュー(FlippedView)に回答文字列をロードするのに苦労しています。誰かがこれを手伝うことができますか?

以下は私が使用しているコードです。誰かがさらに質問があるか、説明が必要な場合は、私に知らせてください。私は最善を尽くして答えます。

感謝を込めて

ジェームズ

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"
4

0 に答える 0