This is a follow-up to one. In short, I'm using CHCSVParser
to work with a very large CSV file and parse lines in Core Data Entities (on an iPhone). I have to bend parsers and work, and now I am trying to display a progress indicator to the user.
I will ask the app user to provide a list to import with a model controller, but the problem I'm running in is that the parser is running, while the screen "stuck" "And the model vicious looks frozen (it seems that it has not been sacked). No matter how I organize this code, it seems that the parser is running while locking everything, so the model VC is not animated and the progress indicator (a simple UIVU and UILBL) is hidden.
I have not programmed with threads before, but it seems to me that I think a little bit. How can I address it?
Thank you!
code:
==== Callback method from model VC ==== // // reject model VC // [self-reject Model view controller permission : No]; // // See progress progress indicator // see progress = [[UIView alloc] initWithFrame: CGRactMake (0,0,320,480)]; ProgressView.backgroundColor = [UIColor colorWithRed: 0 green: 0 blue: 0 alpha :. 9]; UILABL * ProgressLabel = [[UILabel alloc] initWithFrame: CGRectMake (10, 150, 300, 60)]; ProgressLabel.backgroundColor = [UIColor clear collar]; ProgressLabel.textAlignment = UITextAlignmentCenter; ProgressLabel.tag = 12345; ProgressLabel.text = NSLocalystString (@ "Start importing ...", @ ""); ProgressLabel.textColor = [UIColor whiteColor]; [Add Progress Special: Progress Label]; [Self.view addSubview: progressView]; // // If a name was given, create a list with the given name, then parse the selected CSV file in // if (listName! = Zero) {// Create a new list object and start the current list Set it NSError * Error = Zero; NSEntityDescription * ed = [NSEntityDescription EntityForName: @ Managed Object Contact in "FOList": Contents] Managed Objects; FOList * theList = [NSEntityDescription insertNewObjectForEntityForName: Managed object contexts in [ad name]: ManagedAccount.net]; TheList.name = listName; If (! [ManagedObjectContext save: & Error]) {NSLog (@ "Error saving new list!% @% @", [Error localized description], [Error user information]); } CurrentList = theList; // // Hold the appropriate file / NSArray * path = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, yes); NSString * document directory = [path item overindexx: 0]; NSURL * Input File URL = [NSUr File URLWithPath: [Documents Directory StringBapping Packager: Selected Filename]]; // // start parsing / NSStringEncoding encoding = 0; CHCSVParser * p = [[CHCSVParser alloc] initWithContentsOfCSVFile: [inputFileURL route] used encoding: and encoding error: zero]; [P Setpers DeLaygate: Self]; NumRowsParsed = [NSNumber numberIncluding: 0]; [Purse]; [P release];
Here I answered my own question. After a bit of excavation I found a good article NSOperationQueues were a bit overkill here, and I needed all the - performSelectorInBackground: withObject:
and - performSelectorOnMainThread: withObject: waitUntilDone:
. These methods will handle the background and main threads for you and make it as easy as pie!
Comments
Post a Comment