First of all excuse my english because I'm french :-)
I'm a iOS dev beginner and I try to use Master Detail view with XCode 4.4.
What I want:
My master view contains UITableView with Prototype cells. When I click on my cell, I want to see the Detail View.
Here is my code:
MasterViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
NSDictionary* instrument = [Instruments objectAtIndex:indexPath.row];
NSLog(@"instrument: %@",instrument);
NSString* status = [instrument objectForKey:@"status"];
NSLog(@"status: %@",status);
NSString* imageName = [NSString stringWithFormat:@"%@48.png", [status lowercaseString]];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
imgView.image = [UIImage imageNamed:imageName];
cell.imageView.image = imgView.image;
// Set up the cell...
NSString *cellValue = [instrument objectForKey:@"id"];
cell.textLabel.text = cellValue;
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"masterToDetails"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDictionary* instrumentDetails = [Instruments objectAtIndex:indexPath.row];
[[segue destinationViewController] setDetailItem:instrumentDetails];
}
}
Of course I have a segue in my storyboard linking my prototype cell to the detail view with "masterToDetails" for identifier.
When I click on a prototype cell in my master table, prepareForSegue is not called. Why?
Then when I try to force segue call with:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"masterToDetails" sender:[self.tableView cellForRowAtIndexPath:indexPath]];
}
I have the following error: NSInvalidArgumentException, reason: Receiver has no segue with identifier masterToDetails
But it exists in my storyboard!
Maybe the way I use MasterDetail is wrong or maybe it's a stupid error from me...
Tell me if you want other details from my application.