你解释下面的崩溃日志......
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController createAddressBookCopy]: unrecognized selector sent to instance 0x5908300'.
这是什么意思?
我的代码在这里....
-(NSString *)pathOfFile{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentsDirectory=[paths objectAtIndex:0];
//lastName.text=[paths objectAtIndex:0];
return [documentsDirectory stringByAppendingFormat:@"contacts.plist"];
}
-(IBAction)createAddressBookCopy{
UIActionSheet *actionSheet=[[UIActionSheet alloc]
initWithTitle:@"Wanna create a copy of Addressbook?"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Yeah!!!"
otherButtonTitles:nil];
[actionSheet showInView:self.view];
[actionSheet release];
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
NSMutableArray *masterList = [[NSMutableArray alloc] init];
for (int i = 0; i < nPeople; i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
CFStringRef fName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
CFStringRef lName = ABRecordCopyValue(ref, kABPersonLastNameProperty);
NSString *contactFirstLast = [NSString stringWithFormat: @"%@", (NSString *)lName];
CFRelease(fName);
CFRelease(lName);
[masterList addObject:contactFirstLast];
//[contactFirstLast release];
}
//self.list = masterList;
[masterList writeToFile:[self pathOfFile] atomically:YES];
[masterList release];
}
//creating action sheet
-(void)actionSheet:(UIActionSheet *) actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex!=[actionSheet cancelButtonIndex]) {
UIAlertView *alert=[[UIAlertView alloc]
initWithTitle:@"Copy creaeted."
message:@"New copy is contacts.plist"
delegate:self
cancelButtonTitle:@"DONE"
otherButtonTitles:nil
];
[alert show];
[alert release];
}
}
答案 0 :(得分:1)
您已将消息createAddressBookCopy
发送到UIViewController
个对象。该应用程序崩溃是因为UIViewController
没有该名称的方法。
答案 1 :(得分:1)
这意味着您有一些代码试图在createAddressBookCopy
实例上调用UIViewController
方法。根据{{3}},不存在这样的方法,因此崩溃。
答案 2 :(得分:1)
这意味着程序中的某个对象尝试向createAddressBookCopy
发送UIViewController
消息,但此UIViewController
对象未实现此类方法
答案 3 :(得分:1)
UIViewController没有名为createAddressBookCopy的方法。我怀疑你有一个UIViewController子类确实有这个方法,但由于某种原因你正在调用超类。如果您正在使用界面构建器并且未正确连接出口,则有时会发生这种情况。
答案 4 :(得分:1)
检查IBAction
是否正确连接。我认为它没有正确连接。检查.h文件中方法的声明是否相同。