views:

19

answers:

0

Hi I am making a ipad application , in this i am having one table view and on selection of table did select cell method i am saving different videos to NSBundle (i.e. locally to my ipad ) Now when processing of saving one video is being going on and till the video is not saved, if i click on the other cell and wait for the video to be downloaded then when i check the locally saved video then the video being saved is of the url which was of the first click and not the second(which is wrong as i have clicked on second cell it should save video with url on second cell ) .

My code which i call on the cell click event is as follows :

-(bool)startTheBackgroundJob

{

NSString* strUrl = VIDEO_URL;
strUrl = [strUrl stringByAppendingString:[ary objectAtIndex:a]];
NSURL *url =[NSURL URLWithString:strUrl];
NSData *videoData;= [[NSData alloc]initWithContentsOfURL:url];
NSLog(@"data%@",videoData);
[url release];
NSArray *paths= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@",[paths objectAtIndex:0]] ]; 
NSString* strTemp = @"/";
strTemp = [strTemp stringByAppendingString:[ary objectAtIndex:a]];

NSString *appFile= [documentsDir stringByAppendingString:strTemp];        
NSLog(@"%@",appFile);

BOOL success = [videoData writeToFile:appFile atomically:YES];
if (success) 
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"VideoSaved"];
else
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"VideoSaved"];

//[videoData release];
return success;    

}

PS :in my code i am using NSArray ary which consist of different url and on click event of cell object from ary is being fethced at the indexpath.row Here the problem which appears to me is of the NSdata *videoData

Thanks in advance ..