views:

99

answers:

1

Hi, i didn't really know how to title this question, but here's a thing that really kills me: In my app i have a UITableView, UISegmentedControl and UINavigationBar. Once UISegmentedControl gets one of its segments selected i want to show a UIActivityIndicatorView on the UINavigationBar and then parse an xml file and present the results in a table. Everything works almost as i want it to, except one thing, the activity indicator view gets added to the uinavigationbar after the parser finishes, even though the method showLoading that adds UIIndicatorView to UINavigationBar gets before parser is initialised. Can anyone explain it? is there something i might be missing? maybe the ui needs to get redrawn? thanks peter

A: 

It looks that you parse your xml in main thread and so it becomes blocked for UI changes. Try to move xml parsing to separate thread (e.g. by calling your parsing method via -performSelectorInBackground:)

Edit: Actually you're (almost certainly) using autorelease implicitly in your application - as many standard functions return autoreleased objects. When you're running your functions on separate thread you need to create NSAutoreleasePool object there to handle autoreleased objects and avoid memory leaks (see Autorelease Pools in docs). So your parseXML function must look like:

- (void)parseXML{
   NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
   ... //xml parsing routines etc
   [pool release];
}
Vladimir
Hi!thanks so much for answer, but now when i tried parsing with performSelectorInBackground i get a bunch of NSAutoreleaseNoPool errors, even though i'm not using autorelease at all in the app.
dusker
Hi again,actually for some weird reason the errors are also about some UI elements of the main view (for the reference i call the parser in the other class).greetings
dusker
what kind of errors they are? May be it is better to ask about them in separate question if the problems with activity indicator and memory leaks are solved?
Vladimir
it's the errors about leakage, but they address some UI elements of a class that has the object that parses xml
dusker
it is really hard to say anything without seeing the code
Vladimir