我試圖做一個簡單的筆記應用程序。當我運行該項目時,在調試區域,它說;終止應用程序由於未捕獲的異常「NSInvalidArgumentException」 - 無法識別的選擇
[1752:19d03] -[TableViewController createEditableCopyOfDatabasteIfNeeded]: unrecognized selector sent to instance 0xa147d20
[1752:19d03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TableViewController createEditableCopyOfDatabasteIfNeeded]: unrecognized selector sent to instance 0xa147d20'
我的代碼,包括createEditableCopyOfDatabasteIfNeeded,是;
- (void)createEditableCopyOfDatabaseIfNeeded {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentDirectory = [self applicationDocumentsDirectory];
NSString *writableDBPath = [documentDirectory stringByAppendingPathComponent:@"NotesList.plist"];
BOOL dbexits = [fileManager fileExistsAtPath:writableDBPath];
if (!dbexits) {
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"NotesList.plist"];
NSError *error;
BOOL success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
}
這裏的問題在哪裏? 這可能很簡單,但我是Xcode的新手。 感謝您的幫助
您的問題首先是'無法識別selector'這是因爲你試圖調用一個叫做'createEditableCopyOfDatabaseIfNeeded'在'UITableView'方法,它不知道它是什麼。你在哪裏調用'createEditableCopyOfDatabaseIfNeeded'?其次你不需要顯示'main.m',如果你沒有捕獲到被稱爲'未捕獲的異常'的異常並且會終止你的應用程序,它就會結束退出。按照Epatel的回答說,這個例外本身就是真正的中斷。 – Popeye