Still "somewhat" of a newbie... I have an NSMutableArray that stores filenames - when a user clicks a UITableView the corresponding selected cell will pass the certain filename in the array to MPMoviePlayerController to play. It works, however if I exit out of the viewcontroller and come back, only the last video that I played will work, if I select any other table entry, I get a crash with "EXEC_BAD_ACCESS". So I'm assuming the array is being released when the view controller disappears Here is the code:
first off: "NSMutableArray *filenameArray;" is in the .h file
(void)viewDidLoad
{
[super viewDidLoad];
//filenameArray = [[[NSMutableArray alloc] initWithCapacity: 500] autorelease];
filenameArray = [[NSMutableArray alloc] initWithCapacity: 500];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSString *fullPath = [[NSString alloc] init];
fullPath = [[_importableVideoDocs objectAtIndex:indexPath.row] description];
NSLog(@"Full path is: %@", fullPath);
[filenameArray addObject:fullPath];
NSString *fileName = [fullPath lastPathComponent];
[fullPath release];
cell.textLabel.text = fileName;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Tapping row %d", indexPath.row);
NSUInteger i = (indexPath.row);
NSString *test = [[filenameArray objectAtIndex:i] description];
//CRASH HAPPENS HERE IF VIEW CONTROLLER IS DISMISSED AND THEN APPEARS AGAIN
//when view disappears is filenameArray released? do I need to retain?
NSLog(@"%@", test);
moviePlayer = [[[CustomMoviePlayerViewController alloc] init] autorelease];
// Show the movie player as modal
[self presentModalViewController:moviePlayer animated:YES];
// Prep and play the movie
[moviePlayer readyPlayer:test];
}
So my "newbie" question is, how do I retain this to stop the EXC_BAD_ACCESS crash when I click the table when the view appears for the second time? or if I'm not on the right track to the answer, what do I need to do to stop this crash? If anyone could help me with how I might solve this it would be greatly appreciated! Thanks!