2013-03-28 4 views
0

최근에 사용자가 주문 목록에 항목을 추가 할 수있는 앱을 만들고 버튼을 눌러 팝업 테이블보기를 호출하고 핵심 데이터를 사용하여 저장할 수 있습니다. 자료.UITableView가 데이터를 다시로드하지 않습니다.

앱에 기본 테이블보기가 있으며 슬라이딩 메뉴가있는 Facebook 앱처럼 각 행에 다른 테이블보기가 표시됩니다.

응용 프로그램의 레이아웃은 다음과 같습니다 :

|---------------------------------------------------------------| 
|            ______________ | 
|            |Popover Button|| 
|            -------------- | 
|---------------------------------------------------------------| 
|-----------------------------|First table item 1    | 
|Row to call the First table |         | 
|-----------------------------|---------------------------------| 
|Row to call the Second table |First table item 2    | 
|-----------------------------|         | 
|Row to call the Third table |---------------------------------| 
|-----------------------------|First table item 3    | 
|Row to call the Fourth table |         | 
|-----------------------------|---------------------------------| 

문제는 다음 시나리오에서 발생된다

  1. 시작 응용 프로그램.

  2. 첫 번째 표보기를 선택하십시오.

  3. 일부 항목을 목록에 추가하려면 추가 버튼을 누릅니다.

  4. popover 테이블보기를 보려면 popover 버튼을 누릅니다 (목록이 업데이트되었습니다).

  5. 팝업 테이블보기를 닫습니다.

  6. 더 많은 항목을 목록에 추가하십시오.

  7. popover 버튼을 누르십시오 (목록은 동일하게 유지되며 테이블보기는 업데이트되지 않았습니다).

  8. 다른 테이블보기로 이동 (또는 같은 다시 테이블보기 전화) 다시

  9. 눌러 팝 오버 버튼 (목록은 다음 업데이트되었습니다).

누구든지 나를 분류 할 수 있습니까? 감사! ,

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.navigationItem.leftBarButtonItem = self.editButtonItem; 

    //load lists 
    NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Dish"]; 
    fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"created" ascending:YES]]; 

    self.lists = [self.managedObjectContext executeFetchRequest:fetchRequest error:nil]; 

    [self.tableView reloadData]; 
} 

- (NSManagedObjectContext *)managedObjectContext 
{ 
    return [(AppDelegate *) [[UIApplication sharedApplication] delegate] managedObjectContext]; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
    // Delete the row from the data source 

     [self.managedObjectContext deleteObject:[self.lists objectAtIndex:indexPath.row]]; 
     [self.managedObjectContext save:nil]; 

     NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Dish"]; 
     fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"created" ascending:YES]]; 

     self.lists = [self.managedObjectContext executeFetchRequest:fetchRequest error:nil]; 

     [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
    else if (editingStyle == UITableViewCellEditingStyleInsert) { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
    } 
} 

DetailView.m

- (IBAction)popupAddToOrderButtonPressed:(id)sender 
{ 
    OrderViewController *orderView = [[OrderViewController alloc] initWithNibName:@"OrderViewController" bundle:nil]; 
    Dish *newList = [NSEntityDescription insertNewObjectForEntityForName:@"Dish" inManagedObjectContext:orderView.managedObjectContext]; 
    newList.created = [NSDate date]; 
    newList.title = self.popupTitle.text; 
    [orderView.managedObjectContext save:nil]; 
    orderView.lists = [orderView.lists arrayByAddingObject:newList]; 
} 
+1

위의 코드를 디버깅하지 않은 이유는 테이블에 새 데이터가 표시되지 않는 이유를 확인하는 것이지만 어려운 일입니다. 'NSFetchedResultsController' 문서를 확인하십시오. 핵심 데이터 저장소의 데이터를 표시하는 'UITableView'의 데이터 소스로 설계되었으며이 구현을 훨씬 단순하게 만듭니다. – XJones

답변

0

나는 NSNotification 전체 응용 프로그램을 통해 이동하므로이 문제를 해결하기 위해 NSNotification을 사용

OrderView.m : 아래

코드입니다 그래서 popover 테이블 뷰에 NSNotification 리시버를 설정하고 popover 테이블 뷰가 알림을 받으면 가져 오기 요청을 수행하여 데이터를 가져옵니다.

추가 단추를 누르면 알림을 보내어 팝업보기에서 데이터를 가져 오도록 요청합니다.

그래서 문제가 해결되었습니다.

관련 문제