3

まず第一に、私はフランス語なので英語を失礼します:-)

私はiOS開発の初心者で、XCode4.4でマスター詳細ビューを使用しようとしています。

私が欲しいもの:

私のマスタービューには、プロトタイプセルを含む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が呼び出されません。なんで?

それから私がセグエコールを強制しようとすると:

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

次のエラーが発生します:NSInvalidArgumentException、理由:レシーバーに識別子masterToDetailsのセグがありません

しかし、それは私のストーリーボードに存在します!

たぶん、MasterDetailの使い方が間違っているか、私からのばかげたエラーかもしれません...

私のアプリケーションから他の詳細が必要な場合は教えてください。

4

1 に答える 1

8

セグエをセルから次のviewControllerにリンクする代わりに、viewController(ビューの下にある小さなオレンジ色のアイコン)から次のviewControllerにドラッグします。次に、セグエに識別子を付けてから、次を使用します。

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

(スペルミスを軽減するために、セグエ識別子をコピーして貼り付けます)。

于 2012-09-03T20:40:31.163 に答える