Я пытаюсь создать приложение очереди ресторанов, чья первая страница будет с тремя кнопками, одна из которых - «Новая резервация». Когда вы нажмете на него, откроется новое представление, в котором будут указаны имя клиента, номер телефона и общее количество людей, официант войдет в расчетное время для своего заказа и нажмите enter, который сохранит все эти значения в plist. Я имею в виду видео youtube для создания plist, но у меня есть класс контроллера представления, в котором я инициализирую plist, а также класс NewReservation, который управляет данными сохранения. Согласно видео, я создаю plist в методе viewDidLoad, а также скопирую несколько строк его в IBAction кнопки «ввести данные». Я перепутался и не могу получить доступ к значениям в моем классе NewReservation, пожалуйста, уточните. Спасибо.Создание Plist iOS
ViewController.h
#import <UIKit/UIKit.h>
@class NewReservation;
@interface ViewController : UIViewController
@property (nonatomic , strong) NewReservation *Res;
@end
ViewController.m
#import "ViewController.h"
#import "NewReservation.h"
@interface ViewController()
@end
@implementation ViewController{
NSMutableArray *phoneNumbers , *name , *noOfPeople , *estTime;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.Res = [[NewReservation alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Property List.plist"];
if(![[NSFileManager defaultManager] fileExistsAtPath:plistPath]){
plistPath = [[NSBundle mainBundle] pathForResource:@"Property List" ofType:@"plist"];
}
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSDictionary *temp = (NSDictionary *) [NSPropertyListSerialization propertyListWithData:plistXML options:NSPropertyListMutableContainersAndLeaves format:&format error:&errorDesc];
if(!temp){
NSLog(@"Error Reading plist: %@ , format: %lu",errorDesc , format);
}
name = [NSMutableArray arrayWithArray:[temp objectForKey:@"name"]];
phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"phoneNumbers"]];
noOfPeople = [NSMutableArray arrayWithArray:[temp objectForKey:@"noOfPeople"]];
estTime = [NSMutableArray arrayWithArray:[temp objectForKey:@"estTime"]];
//Confused how to go further
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
NewReservation.h
#import <UIKit/UIKit.h>
@interface NewReservation : UIViewController{
}
@property (weak, nonatomic) IBOutlet UITextField *name;
@property (weak, nonatomic) IBOutlet UITextField *phoneNumber;
@property (weak, nonatomic) IBOutlet UITextField *noOfPeople;
@property (weak, nonatomic) IBOutlet UITextField *estTime;
- (IBAction)nameReturn:(id)sender;
- (IBAction)enterDetails:(id)sender;
@end
NewReservation.m
#import "NewReservation.h"
@implementation NewReservation
- (IBAction)enterDetails:(id)sender{
if([self.name.text isEqualToString:@""] || [self.phoneNumber.text isEqualToString:@""] || [self.noOfPeople.text isEqualToString:@""] || [self.estTime.text isEqualToString:@""]) {
UIAlertView *error = [[UIAlertView alloc] initWithTitle:@"Oops" message:@"You must complete all fields!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[error show];
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Property List.plist"];
//Cant continue here cause its confusing me, i need to add the values and update the list everytime a new 'name,noOfPersons,phoneNumber,estTime
//is entered.
}
@end
Перейдите по ссылке http://stackoverflow.com/questions/5853735/how-can-we-create-our-own-plist-file-in-a-xcode-project – AJS