iPhone崩溃日志

时间:2011-05-06 09:41:30

标签: iphone

你解释下面的崩溃日志......

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

5 个答案:

答案 0 :(得分:1)

您已将消息createAddressBookCopy发送到UIViewController个对象。该应用程序崩溃是因为UIViewController没有该名称的方法。

答案 1 :(得分:1)

这意味着您有一些代码试图在createAddressBookCopy实例上调用UIViewController方法。根据{{​​3}},不存在这样的方法,因此崩溃。

答案 2 :(得分:1)

这意味着程序中的某个对象尝试向createAddressBookCopy发送UIViewController消息,但此UIViewController对象未实现此类方法

答案 3 :(得分:1)

UIViewController没有名为createAddressBookCopy的方法。我怀疑你有一个UIViewController子类确实有这个方法,但由于某种原因你正在调用超类。如果您正在使用界面构建器并且未正确连接出口,则有时会发生这种情况。

答案 4 :(得分:1)

检查IBAction是否正确连接。我认为它没有正确连接。检查.h文件中方法的声明是否相同。

相关问题