Ios5 使用原型单元执行segue

Ios5 使用原型单元执行segue,ios5,uitableview,segue,xcode4.4,Ios5,Uitableview,Segue,Xcode4.4,首先请原谅我的英语,因为我是法国人:-) 我是一名iOS开发新手,我尝试在XCode 4.4中使用Master Detail view 我想要什么: “我的主视图”包含带有原型单元格的UITableView。当我单击我的单元格时,我想查看详细视图 这是我的代码: MasterViewController.m - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)in

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

我是一名iOS开发新手,我尝试在XCode 4.4中使用Master Detail view

我想要什么:

“我的主视图”包含带有原型单元格的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];
    }
}
当然,我的故事板中有一个序列,将我的原型单元链接到细节视图,标识符为“masterToDetails”

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

然后,当我尝试使用以下命令强制segue调用时:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"masterToDetails" sender:[self.tableView cellForRowAtIndexPath:indexPath]];
}
我有以下错误:NSInvalidArgumentException,原因:接收器没有标识符masterToDetails的segue

但它存在于我的故事板中

也许我使用MasterDetail的方式是错误的,也许这是我的愚蠢错误


告诉我是否需要我的应用程序中的其他详细信息。

不要将您的序列从单元格链接到下一个viewController,而是从viewController(视图下方的橙色小图标)拖动到下一个viewController。 然后确保为该段提供标识符,然后使用:

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

(复制并粘贴您的单元标识符,以减少任何拼写错误)。

此外,请检查序列图像板中单元的重用标识符。根据您的代码,它应该是“Cell”FWIW,这个简洁但详细的答案比OP-ty顶部过于冗长的重复链接价值高100倍