用原型单元执行segue

Dor*_*e M 3 uitableview ios5 segue xcode4.4

首先请原谅我的英语,因为我是法国人:-)

我是iOS开发者,我尝试使用XCode 4.4的Master Detail视图.

我想要的是:

我的主视图包含带原型单元格的UITableView.当我点击我的单元格时,我想看详细视图.

这是我的代码:

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];
    }
}
Run Code Online (Sandbox Code Playgroud)

当然,我的故事板中有一个segue将我的原型单元格链接到详细视图,其中"masterToDetails"用于标识符.

当我在主表中单击原型单元格时,不会调用prepareForSegue.为什么?

然后,当我尝试强制segue调用时:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"masterToDetails" sender:[self.tableView cellForRowAtIndexPath:indexPath]];
}
Run Code Online (Sandbox Code Playgroud)

我有以下错误:NSInvalidArgumentException,原因:Receiver没有标识符masterToDetails的segue

但它存在于我的故事板中!

也许我使用MasterDetail的方式是错误的,也许这对我来说是一个愚蠢的错误......

如果您需要我的申请中的其他详细信息,请告诉我

Dar*_*ren 8

不是将segue从单元格链接到下一个viewController,而是从viewController(View下面的小橙色图标)拖动到下一个viewController.然后确保你给segue一个标识符然后使用:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"masterToDetails" sender:indexPath];
}
Run Code Online (Sandbox Code Playgroud)

(复制并粘贴您的segue标识符以减轻任何拼写错误).