0
+(DetailViewController *) instance{
    return (DetailViewController *)[[UIApplication sharedApplication]delegate];
}

-(void)tapped:(UITapGestureRecognizer *)recognizer {
    [[DetailViewController instance]showViewInFullScreen:self withModel:self.messageModel];
}

DetailViewController.m

-(void)showViewInFullScreen:(UIViewExtention*)viewToShow withModel:(MessageModel*)model{
    [viewController showViewInFullScreen:viewToShow withModel:model];
}

DetailViewController クラスにある showViewInFullScreen を呼び出すことができないタップされたメソッドに到達すると、アプリは次のメッセージで終了します。

NSInvalidArgumentException'、理由:

'-[AppDelegate showViewInFullScreen:withModel:]: 認識されないセレクターがインスタンスに送信されました

ありがとう。

4

1 に答える 1

0

アプリのデリゲートを DetailViewController クラスにキャストするのはなぜですか?

DetailViewController クラスのシングルトンを作成する場合は、次のようにする必要があります (ARC を使用していると仮定します)。

+(DetailViewController *) instance{
    // Create a singleton instance of the class
    static DetailViewController *sharedInstance = nil;
    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{
        sharedInstance = [[self alloc] init];
    });

    return sharedInstance;
    }
}
于 2012-12-03T11:29:22.740 に答える