缺少方法签名会导致应用程序中止吗?

时间:2011-03-07 21:07:35

标签: objective-c

以下是错误消息:

警告:'ReaderAppDelegate'可能无法响应'-checkForDatabase' (没有匹配方法签名的消息将被假定为返回'id'并接受'...'作为参数。

我在下面的代码中的'checkForDatabase'方法中放了一个断点,它从来没有到达那里......应用程序死了。我假设他上面的警告与中止有关。我该如何解决?我是否必须在.h文件中声明'checkForDatabase'?

//---------------    application finished launching    ----------------|
- (void)applicationDidFinishLaunching:(UIApplication *)application  {
    //  create the d/b or get the connection value
    [self checkForDatabase];    

}

//--------------    check for database or create it    ----------------|
- (void)checkForDatabase  {

    NSFileManager *filemanager = [NSFileManager defaultManager];
    NSString *databasePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] 
            stringByAppendingString:@"/ppcipher.s3db"];

    if(![filemanager fileExistsAtPath:databasePath]) {  //Database doesn't exist yet, so we create it...
        NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/ppcipher.s3db"];
        // remainder of code goes here...
    }
}

3 个答案:

答案 0 :(得分:1)

正如您所提到的,您需要在接口中声明该函数,或者动态(即:runtime)绑定将不知道该方法是否存在。

答案 1 :(得分:0)

在类的界面中声明-checkForDatabase方法是个好主意,但我不认为这是导致崩溃的原因。查看控制台是否有可能指示崩溃原因的消息。

答案 2 :(得分:0)

您需要在头文件中或在实现文件中的私有类中声明checkForDatabase。您还可以在applicationDidFinishLaunching的实现之上定义方法实现。