2011-02-03 8 views
1

私はplistを持っているアプリには:iphoneでplistの配列オブジェクトを書き込む方法は?

root ---> dictionary 
    cell ----> array 
    item0 ---> string 
    item1 ----> string 

のように。 navigation baradd buttonを保持し、このplist &テーブルビューからのデータを保持tableView

。私がクリックすると、text field &を持つ別のビューがbuttonにプッシュされます。私はボタンをクリックして、最後のオブジェクトの配列のテキストフィールドのテキストをplistに保存します。

テーブルビューをリロードすると、データは常にplistに格納されます。

答えて

3

コードがある....このことができます

-(void)dataFetching 
{ 
NSMutableDictionary *categoryList = [[NSMutableDictionary alloc] initWithContentsOfFile:@"Give the file path"]; 
NSMutableArray *array =(NSMutableArray *) [categoryList valueForKey:@"write the array name here"]; 

/* hope u know how a table loads data from the array */ 

/*whenever add button is pressed on the table view cell, view would be shown with a textfield and a button, isn't it? */ 

/* by setting the delegate for textfield, using the textfieldDidEnterEditing: method capture the text from the textfield*/ 
// for example, 
NSString *testStr = @"test String"; //[textfield text]; 
//Now, 

int lastItemIndex = [array count]; 
[array insertObject:testStr atIndex:lastItemIndex]; 
// and whenever you want you can save it on to the file like this 

[categoryList writeToFile:@"Give the file path" atomically:YES]; 

[categoryList release]; 
} 

希望。 ....

+0

この投稿を再開すると、私はファイルからmustabledictionaryを読み込み、更新してファイルに書き直す方法を知りたい – JackTurky

1

チェック方法NSDictionaryのNSArrayのと

ため

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag 

ともここ

+ (id)arrayWithContentsOfFile:(NSString *)aPath 
+ (id)dictionaryWithContentsOfFile:(NSString *)path 
関連する問題