Hi guys,
I just started with iPhone Development so don't be too hard on me.
So in my first view I have this:
in the .h:
Code:
NSArray *listOfDocs;
in the .m:
Code:
- (void)viewDidLoad {
NSString *documentsDirectory = [NSHomeDirectory()
stringByAppendingPathComponent:@"Documents"];
NSError *error = nil;
listOfDocs = [[NSFileManager defaultManager]
contentsOfDirectoryAtPath:documentsDirectory error:&error];
self.navigationItem.title = @"Documents";
self.navigationItem.rightBarButtonItem = self.editButtonItem;
[super viewDidLoad];
}
That grabs the contents of the documents directory and puts them into an array.
Now I want to display the array in my navigation view... so I do this:
Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return[listOfDocs count];
}
- (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 *cellValue =[listOfDocs objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
So far that works! But now I want to load a new view and have the name of the view be the name of the item clicked on. So I try this:
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
EditViewController *editView = [[EditViewController alloc] initWithNibName:@"EditViewController" bundle:nil];
[editView setTitle:[listOfDocs objectAtIndex:indexPath.row]];
// editView.title = @"name";
[self.navigationController pushViewController:editView animated:YES];
}
That crashes the app with a "EXC_BAD_ACCESS"
when I comment out
Code:
[editView setTitle:[listOfDocs objectAtIndex:indexPath.row]];
it runs fine, the name just does not change.
I'm not sure what I am doing wrong.. can someone help please?
Thanks