所以我試圖解了一起 - 我做了一個小的單一視圖的應用程序從:-)學習試圖在plist中寫入數據 - 幾乎沒有
我想實現,你可以看到通過適應的代碼和圖像是我有一個textField和提交到UITable按鈕 - 第一個UIView我嵌入在導航視圖中,以便UITableView可以顯示它的結果。現在我得到2個錯誤,我知道我忘記了一些東西,但我無法弄清楚如何寫入聲明它們。
AddingViewController.h
@interface AddingViewController : UIViewController {
Dfetch *dao;
IBOutlet UITextField *addToPlistTxt;
IBOutlet UITableView *table;
NSArray *testList;
}
@property (retain, nonatomic) IBOutlet UITextField *addToPlistTxt;
@property (retain, nonatomic) IBOutlet UITableView *table;
@property (retain, nonatomic) NSArray *testList;
-(IBAction)makeKeyBoardGoAway;
-(IBAction)submitToPlistAction;
@end
代碼AddingViewController.m的代碼:
@implementation AddingViewController
@synthesize addToPlistTxt;
@synthesize table;
@synthesize testList;
//Not very elegant way to dismiss keyboard, but it will do for the excersize
-(IBAction)makeKeyBoardGoAway{
[addToPlistTxt resignFirstResponder];
}
-(IBAction)submitToPlistAction{
NSString *path = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
NSString *addLine = self.addToPlistTxt.text;
NSArray *values = [[NSArray alloc] initWithObjects:addLine, nil];
NSArray *keys = [[NSArray alloc] initWithObjects:NAME_KEY, nil];
NSDictionary *dict = [[NSDictionary alloc] initWithObjects:values forKeys:keys];
[self.testList addObject:dict];
[self.testList writeToFile:path atomically:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
@end
現在我只是想了解這一點,所以我粘貼整個文件,以便我能看到我出錯了。
的錯誤是:
NSArray *keys = [[NSArray alloc] initWithObjects:NAME_KEY, nil];
和
[self.testList addObject:dict];
一旦我得到了這2個排序,應該是設置爲我的數據添加到我的plist?
我已經添加下面的截圖,所以你不需要可視化的UI :-)
我希望這一切是有道理的 - 感謝:-)
乾杯任何意見傑夫
你的大問題仍然需要更多的細節:你得到了什麼樣的錯誤?什麼是「NAME-KEY」定義爲? – 2012-03-27 00:36:14
是的,我知道這是非常抱歉,我只是試圖添加儘可能多的細節,我可以:-)定義Name_Key是我卡住的一件事 - 我不知道在哪裏以及如何做到這一點。我將它稱爲NAME_KEY,因爲它在Plist中被稱爲key下的名稱。 – 2012-03-27 00:39:09