仍然“有点”新手...我有一个NSMutableArray存储文件名 - 当用户单击UITableView时,相应的选定单元格将传递数组中的某个文件名到MPMoviePlayerController播放。它可以工作,但是如果我退出视图控制器并返回,只有我播放的最后一个视频才会起作用,如果我选择任何其他表项,我会碰到“EXEC_BAD_ACCESS”。所以我假设阵列在视图控制器消失时被释放 这里是代码:NSMutableArray导致EXC_BAD_ACCESS在viewcontroller消失后出现崩溃并重新出现
first off:“NSMutableArray * filenameArray;”在.h文件
(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];
}
所以我的“新手”问题是,我该如何保持这种停止EXC_BAD_ACCESS崩溃当我点击表格视图时出现第二次?或者如果我的回答不正确,我需要做些什么来阻止这次事故?如果有人可以帮我解决这个问题,我将非常感谢! 谢谢!
您通常会受益于从断点处逐步完成代码。 Stacktrace也应该帮助你隔离这个。你怎么知道崩溃在这里与正在卸载的视图有关? – Nick 2010-10-08 06:09:41