簡體   English   中英

UITableView在iPhone中具有巨大的(大約一百萬個條目)數據

[英]UITableView with huge(probably 1million entries)data in iphone

我正在開發一個應用程序,該應用程序需要通過在表視圖中進行無限滾動來加載超過一百萬個條目。 每次將發送1000個條目的請求,並且一旦通過JSON庫下載並解析了數據,表就會重新加載。 我已經通過CoreData使用“ setFetchBatchSize = 1000”實現了這一點。

StreamModal *modal = [[StreamModal alloc]init];
              StreamModal *modal = [NSEntityDescription insertNewObjectForEntityForName:@"StreamModal" inManagedObjectContext:managedObjectContext];
                 if([self isNotNull:[streamDataDict objectForKey:@"_id"]])
                     modal.stream_id               = [streamDataDict objectForKey:@"_id"];

-(void)reloaData{
@try {
    NSError *error;
    if (![[self fetchedResultsController] performFetch:&error]) {
        // Update to handle the error appropriately.
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        exit(-1);  // Fail
    }
    NSLog(@"ferchresults count %d",[[_fetchedResultsController fetchedObjects]count]);
}
@catch (NSException *exception) {
    NSLog(@"exception raised in reloadData in streamViewController class %@",exception);
}
@finally {

}
}


- (NSFetchedResultsController *)fetchedResultsController {

if (_fetchedResultsController != nil) {
    return _fetchedResultsController;
}

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"StreamModal" inManagedObjectContext:appDelegate.managedObjectContext];
[fetchRequest setEntity:entity];

NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];

[fetchRequest setFetchBatchSize:1000];
//[fetchRequest setFetchLimit:2000];

NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:appDelegate.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
self.fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;

fetchRequest = nil;
theFetchedResultsController = nil;

return _fetchedResultsController;    

}

這是我使用的代碼,當連接完成加載數據時,我會將數據填充到NSManagedObject Class(StreamModal)中,然后調用reload data.Here問題是應用程序在我將12000個條目加載到表中並崩潰后正在獲取內存異常。 我如何才能在沒有內存異常的情況下加載所有條目。 我是CoreData概念的新手,並且已經通過開發人員指南閱讀了核心數據概念,但是我沒有找到與內存處理相關的任何信息。 請幫我。

我希望您正在使用ARC? 因為您沒有釋放任何初始化的對象。 (如果不是,那是您的答案。)

但是無論如何:您是否嘗試過使用Instruments來查看哪些對象最多增加了內存占用量? 那將是一個很好的起點。

濕婆神

首先,我想回應其他評論,即使用一百萬個項目的單個表視圖確實是一種糟糕的用戶體驗。

對你的問題:

出現內存警告時您在做什么?

至少,您應該遍歷對象數組並修剪對象圖。 這是通過-refreshObject:mergeChanges: 您還應該注意不要遍歷數組太遠。 我會從您的可見對象開始,並向前和向后工作,直到通過-isFault測試開始擊中故障對象。

安德魯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM