2012-01-05 2 views
0

WWDC# 2010의 TableViewUpdates 예제를 사용하고 있습니다. 기본적으로 Apple은 섹션 헤더를 클릭하여 접을 수 있고 확장 가능한 TableView를 만듭니다. 있는 TableView에 대한 데이터는과 같이 viewWillAppear에서 생성됩니다 : 나는 많은 데이터를 가지고 내 경우에 대한 나타났습니다UINavigationController를 사용하여 데이터 캐싱

- (void)viewWillAppear:(BOOL)animated { 

    [super viewWillAppear:animated]; 

    /* 
    Check whether the section info array has been created, and if so whether the section count still matches the current section count. In general, you need to keep the section info synchronized with the rows and section. If you support editing in the table view, you need to appropriately update the section info during editing operations. 
    */ 
    if ((self.sectionInfoArray == nil) || ([self.sectionInfoArray count] != [self numberOfSectionsInTableView:self.tableView])) { 

     // For each play, set up a corresponding SectionInfo object to contain the default height for each row. 
     NSMutableArray *infoArray = [[NSMutableArray alloc] init]; 

     for (Play *play in self.plays) { 

      SectionInfo *sectionInfo = [[SectionInfo alloc] init];   
      sectionInfo.play = play; 
      sectionInfo.open = NO; 

      NSNumber *defaultRowHeight = [NSNumber numberWithInteger:DEFAULT_ROW_HEIGHT]; 
      NSInteger countOfQuotations = [[sectionInfo.play quotations] count]; 
      for (NSInteger i = 0; i < countOfQuotations; i++) { 
       [sectionInfo insertObject:defaultRowHeight inRowHeightsAtIndex:i]; 
      } 

      [infoArray addObject:sectionInfo]; 
      [sectionInfo release]; 
     } 

     self.sectionInfoArray = infoArray; 
     [infoArray release]; 
    } 

} 

,이 비용이 많이 드는 작업이다. 데이터를 캐시하고 싶습니다. 데이터는 viewWillAppear에 있기 때문에 매번 생성됩니다. UINavigationController를 사용하여이 뷰를 스택에 푸시하기 때문에 viewDidLoad에 넣으면이 뷰에서 벗어나 집으로 돌아갈 때 뷰를 다시 만들고 viewDidLoad가 다시 실행되어야합니다. 다시 느려질거야.

이전에 데이터를 캐싱하지 않았으며이를 수행하는 좋은 방법이 무엇인지 궁금합니다. 현재 행 머리글과 행에 대한 모든 데이터는 데이터베이스에 있습니다. 따라서이 뷰가 스택에 푸시되면 데이터를 가져 와서 테이블을 만듭니다. 좋은 메커니즘이 테이블을 만들고 viewController의 후속 푸시에서 더 빨리로드되도록 캐시 또는 뷰를 캐시하는 것이 무엇인지 알지 못했습니다. 감사.

답변

0

표시중인 코드는 테이블 뷰의 데이터 소스를 구성하는 것이며 뷰 자체의 일부는 아닙니다. View Controller Initializer에서이 코드를 실행해야하거나 데이터 소스에서 업데이트해야하는 경우 언제든지 해당 코드를 실행해야합니까?

NSFetchedResultsController 및 해당 대리자 메서드를 사용하여 병렬을 그릴 수 있습니다. 이것들은 뷰 처리 메소드와는 별도로 실행되며, 가져온 결과 컨트롤러는 뷰 컨트롤러의 아이바 (매우 자주) 프로퍼티입니다. 그런 다음 예를 들어, 가져온 결과 컨트롤러가 가져 오기를 완료하면 사례별로 변경 사항을 관리하고 테이블보기 및 해당 컨트롤러와 조정하거나 의도적으로 완전히 다시 가져올 수 있습니다. 뷰는 데이터 소스 유지 보수와는 별도로 완전히 나타나고 사라질 수 있습니다.