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

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

细节视图控制器.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 回答