I have a navigation controller, the rootviewcontroller is a tableview, which will show all file names, when user click the file, will show the file content in contentviewer. User can go back use navigation bar.
The problem is sometimes user use navigation bar go back. The app crashed. say exe-bad-access at cellForRowatIndex this line:
cell.textLabel.text = [books objectAtIndex:indexPath.row];
I spend a lot time to figure out the problem. but can not find where it is wrong. Please help
rootviewController.h
@interface rootviewController:UITableViewController{NSMutablyArray* books;}
rootviewContorller.m
import rootviewController.h;
static NSString *MyIdentifier = @"MyIdentifier";
-(void)awakefromNIb
{
books=[[NSMutalbyArray alloc]init];
NSString *file;
NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent: @"Documents"];
NSDirectoryEnumerator *dirEnum =
[[NSFileManager defaultManager] enumeratorAtPath:docsDir];
while (file = [dirEnum nextObject]) {
if ([[file pathExtension] isEqualToString: @"doc"]) {
[books addObject:file];
}
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
cell.textLabel.text = [books objectAtIndex:indexPath.row];
return cell;
}