0

誰かがこれを手伝ってくれることを願っています。

UITableViewController があり、テーブルセルが選択されたときに NewsArticleViewController という UIViewController に値を渡したいと考えています。テーブルセルからビュー コントローラーへのセグエを作成しました。

以下の prepareForSegue メソッドを呼び出すと:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([[segue identifier] isEqualToString:@"ShowNewsArticle"])
    {
        NSIndexPath *indexPath = [self._tableView indexPathForSelectedRow];
        NSDictionary *article = [_articles objectAtIndex:indexPath.row];
        NSString *articleID = [article valueForKey:@"id"];
        NSLog(@"Trying %@", articleID);

        NewsArticleViewController *detailViewController = [segue destinationViewController];
        detailViewController.articleID = articleID;
    }
}

NSLog は、最後の行でエラーが発生する前に NSString 値を正しく示しています。

エラーが発生します:

2012-12-11 23:08:41.915 My School[4689:c07] -[UIViewController setArticleID:]: unrecognized selector sent to instance 0x8088140
2012-12-11 23:08:41.916 My School[4689:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setArticleID:]: unrecognized selector sent to instance 0x8088140'
*** First throw call stack:
(0x1800012 0x11c5e7e 0x188b4bd 0x17efbbc 0x17ef94e 0x3ca1 0x554ac7 0x554b54 0x1bc899 0x1bcb3d 0xbc3e83 0x17bf376 0x17bee06 0x17a6a82 0x17a5f44 0x17a5e1b 0x1cc87e3 0x1cc8668 0x10d65c 0x1f4d 0x1e75 0x1)
libc++abi.dylib: terminate called throwing an exception

宛先ビュー コントローラーである NewsArticleViewController では、ヘッダーで次のように宣言しました。

@property(strong,nonatomic) id articleID;

そして、メソッドでプロパティを合成しました。私は ARC を使用しています。これが特定の原因かどうかはわかりませんが、これを解決するまで先に進むことはできません。ありがとう。

4

1 に答える 1

2

エラー メッセージでUIViewControllerは、「認識されないセレクター」エラーが報告されています。絵コンテNewsArticleViewControllerでこのシーンのカスタムが指定されていないようです。したがって、UIViewController明らかに理解していないデフォルトを使用していますsetArticleID

Interface Builder で、View Controller の「カスタム クラス」設定を確認します。

ここに画像の説明を入力

カスタム クラスが指定されていない場合は、上の画面のスナップショットのようになります。クラス名を入力するだけです。

于 2012-12-11T23:34:39.900 に答える