Я пытаюсь загрузить plist-данные в UILabels в приложении-шаблоне приложений, которое имеет два представления.Существует анимация, которая позволяет переключаться между видами.
Вот структура plist:
Root...............................(Array)
........Item 0.....................(Dictionary)
.................Question..........(string) ///Hello////
.................Answer............(string) ///Goodbye//
Мне удалось получить строку вопроса для загрузки в первое представление (FlashCard1ViewController), используя ключи (Constants.h), но яя пытаюсь получить строку ответа для загрузки во втором представлении (FlippedView).Может ли кто-нибудь помочь с этим?
ниже приведен код, который я использую, если у кого-то есть дополнительные вопросы или требуется разъяснение, пожалуйста, дайте мне знать, и я сделаю все возможное, чтобы ответить.
с благодарностью
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
Константы.h
#define Question_KEY @"Question"
#define Answer_KEY @"Answer"