Это продолжение предыдущего поста , касающегося CHCSVParser от Dave DeLong .Короче говоря, я использую CHCSVParser
для работы с очень большим CSV-файлом и разбора строк на сущности Core Data (на iPhone).У меня подключен и работает парсер, и теперь я пытаюсь отобразить индикатор прогресса для пользователя.
Я прошу пользователя приложения указать имя для списка, который будет импортирован с помощью контроллера модального представления., но проблема, с которой я сталкиваюсь, заключается в том, что экран выглядит «застрявшим» во время работы анализатора, а модальный VC выглядит замороженным (похоже, он не сбрасывается со счетов).Независимо от того, как я расположил код, кажется, что парсер блокирует все во время работы, поэтому модальный VC не выходит из анимации, а индикатор прогресса (простой UIView и UILabel) скрыт.
Я никогда раньше не программировал темы, но для меня это звучит довольно готово.Как я могу решить эту проблему?
Спасибо!
код:
==== CALLBACK METHOD FROM THE MODAL VC ====
//
// Dismiss the modal VC
//
[self dismissModalViewControllerAnimated:NO];
//
// Set up the progress indicator view
//
progressView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
progressView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.9];
UILabel *progressLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 150, 300, 60)];
progressLabel.backgroundColor = [UIColor clearColor];
progressLabel.textAlignment = UITextAlignmentCenter;
progressLabel.tag = 12345;
progressLabel.text = NSLocalizedString(@"Beginning import...",@"");
progressLabel.textColor = [UIColor whiteColor];
[progressView addSubview:progressLabel];
[self.view addSubview:progressView];
//
// If a name was provided, then create a List with the given name then parse the
// selected CSV file into it
//
if (listName != nil) {
// Create the new List object and set the currentList to point to it.
NSError *error = nil;
NSEntityDescription *ed = [NSEntityDescription entityForName:@"FOList" inManagedObjectContext:managedObjectContext];
FOList *theList = [NSEntityDescription insertNewObjectForEntityForName:[ed name] inManagedObjectContext:managedObjectContext];
theList.name = listName;
if (![managedObjectContext save:&error]) {
NSLog(@"Error saving the new list! %@ %@", [error localizedDescription], [error userInfo]);
}
currentList = theList;
//
// Grab the appropriate file
//
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL *inputFileURL = [NSURL fileURLWithPath: [documentsDirectory stringByAppendingPathComponent:selectedFileName]];
//
// Start the parsing
//
NSStringEncoding encoding = 0;
CHCSVParser *p = [[CHCSVParser alloc] initWithContentsOfCSVFile:[inputFileURL path] usedEncoding:&encoding error:nil];
[p setParserDelegate:self];
numRowsParsed = [NSNumber numberWithInt:0];
[p parse];
[p release];