tags:

views:

183

answers:

1

hi friends, i have made one list of images + respective data in tableview. it takes long time while loading i want to make multithreading two methods

1> parsing of data

2> parsing of images

i want to execute parsing of data first after that i can select any of rows listed even though images not been loaded(/parsed) because the images is parsed after the parsing of data and it takes long time.

from where should i call these both the methods. and how enable the selection on row after parsing of the data... how to do multithread both the methods

waiting for your great responce

Thanking in advance

+1  A: 

You likely don't want to use NSThreads - at least not directly. What you do is subclass NSOperation.

There are a few ways to do what you have in mind. If you know the total number of rows in your table right from the start, then things are simpler:

Make a subclass of NSOperation called MyParseDataOperation. Then make one MyParseDataOperation for each row in your table. When the operation is done, you need to message your main thread with the resulting data.

Code below is full of errors, incomplete. etc.

ie in your MyParseDataOperation class:

MyParseDataOperation

-(id)initWithStuff:(NSURL*)stuff forTableRow:(int)row;
{
blah blah - 
// here is where I make sure I have all the data I need for main() which is called in the background on some random thread at some future time.
}

-(void)main;
{
// use data like Urls, file names, etc passed in to the initWithStuff method
get stuff
parse stuff

// ok now you have the data

NSMutableDictionary* parsedData = [NSMutableDictionary dictionary];

[parsedData setObject:[NSNumber numberWithInt:row] forKey:@"row"];
[parsedData setObject:stuff i figured out forKey:@parsed];

[tableDataSource performSelectorOnMainThread:@selector(dataParsed) withObject:parsedData];

}
Tom Andersen