2011-12-14 4 views
1

나는 카테고리 목록이있는 테이블 뷰가 있습니다. 사용자가 추가 버튼을 누르면 텍스트 필드가있는 alertview가 나타나고 '확인'버튼이 나타나고 텍스트 필드에 입력 된 텍스트가 테이블보기에 추가되어야합니다. 추가 할 수 있지만 plist.so에 추가되지 않습니다. 우리가 다른 시각으로 옮겨 와서 돌아 오면 그건 그냥 사라져 버리는거야.동적으로 입력 한 데이터를 plist에 저장합니다.

-(void)viewDidLoad 
{ 
    NSString *fileForCategoryList = [[NSBundle mainBundle] pathForResource:kCATEGORY_LIST ofType:kP_List]; 
    self.arrayForCategories = [[NSMutableArray alloc]initWithContentsOfFile:fileForCategoryList]; 
} 

- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     [self.arrayForCategories removeObjectAtIndex:indexPath.row]; 
     [self.tableViewC reloadData]; 
    } 
    else if (editingStyle == UITableViewCellEditingStyleInsert) 
    { 
     UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:kYOUR_TITLE message:kEMPTY delegate:self cancelButtonTitle:kCANCEL otherButtonTitles:kOK, nil]; 
     self.myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)]; 
     [self.myTextField setBackgroundColor:[UIColor whiteColor]]; 
     [myAlertView addSubview:self.myTextField]; 
     [myAlertView show]; 
     [myAlertView release]; 
    } 
} 

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
    if ([self.myTextField text]) 
    { 
     [self.arrayForCategories addObject:[self.myTextField text]]; 
    } 
    [self.tableViewC reloadData]; 
} 

답변

1

이 데이터를 plist 파일에 기록한 다음 저장해야합니다. 희망 당신은 응용 프로그램의 번들에서 파일에 액세스하고 있습니다. 처음에 복사본을 만들고 Documents 디렉터리에 저장하십시오. 그런 다음 새 데이터를 추가 할 때 문서 디렉토리의 plist 파일에 쓰면 해당 데이터가 plist에 저장됩니다. 이 tutorial 도움이된다면

[yourData writeToFile:filePath atomically:YES]; 

업데이트를 참조하십시오. (그것을 객체를 추가 할 수 있도록 가변)

EDIT

먼저 배열로 PLIST에서 데이터를 읽는다. 그런 다음이 배열에 새 데이터를 추가합니다.

[yourArray addObject:someObject]; 

그런 다음 모든 객체를 추가 한 후이 배열을 파일에 기록합니다.

+0

약간의 코드 또는 링크와 관련이 있습니까? – Chandu

+0

업데이트 된 답변 확인 – visakh7

+0

ya thanx가 링크를 시도합니다. – Chandu

관련 문제