无法调用实例方法

时间:2012-12-03 10:58:20

标签: objective-c ios5

+(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];
}

当我到达tapped方法时无法调用在DetailViewController类中的showViewInFullScreen.And app终止时显示以下消息。

  

NSInvalidArgumentException',原因:

     

' - [AppDelegate showViewInFullScreen:withModel:]:无法识别的选择器   发送到实例

感谢。

1 个答案:

答案 0 :(得分: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;
    }
}