iphone - NSMutableArray causing EXC_BAD_ACCESS crash after viewcontroller did disappear and re appears -
still "somewhat" of newbie... have nsmutablearray stores filenames - when user clicks uitableview corresponding selected cell pass filename in array mpmovieplayercontroller play. works, if exit out of viewcontroller , come back, last video played work, if select other table entry, crash "exec_bad_access". i'm assuming array being released when view controller disappears here code:
first off: "nsmutablearray *filenamearray;" in .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 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 = (indexpath.row); nsstring *test = [[filenamearray objectatindex:i] description]; //crash happens here if view controller dismissed , appears again //when view disappears filenamearray released? need retain? nslog(@"%@", test); movieplayer = [[[custommovieplayerviewcontroller alloc] init] autorelease]; // show movie player modal [self presentmodalviewcontroller:movieplayer animated:yes]; // prep , play movie [movieplayer readyplayer:test]; }
so "newbie" question is, how retain stop exc_bad_access crash when click table when view appears second time? or if i'm not on right track answer, need stop crash? if me how might solve appreciated! thanks!
exc_bad_access means you're trying use variable has been released. if crash happens indicated either array or object stored in array. can try adding more nslogs before crash, nick suggested, debugger friend.
if had guess, i'd try following:
nsstring *fullpath = [[nsstring alloc] initwithstring:[[_importablevideodocs objectatindex:indexpath.row] description]];
i think way you're coding allocs string, leaks when it's replaced description. description think autoreleased, when release later bad stuff might happen. using initwithstring ensure right retain count.
Comments
Post a Comment