2011-05-06 306 views
1

你解釋foollowing崩潰日誌......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]; 
    } 
} 
+0

你的方法'createAddressBookCopy'有問題。你可以發佈你的代碼,如何調用和定義方法 – visakh7 2011-05-06 09:44:26

回答

1

檢查您的IBAction是否連接正確。我認爲它沒有正確連接。檢查.h文件中的方法聲明是否相同。

+0

是否有基於視圖和基於tabbar的應用程序之間的連接有任何區別? – Shahriar 2011-05-06 09:54:11

+0

如何在視圖控制器的.h文件中聲明這種方法,以及如何連接它們? – visakh7 2011-05-06 09:55:33

+0

- (NSString *)pathOfFile; - (IBAction)createAddressBookCopy; – Shahriar 2011-05-06 09:58:06

1

你發送的消息createAddressBookCopyUIViewController對象。該應用程序崩潰,因爲UIViewController沒有該名稱的方法。

+0

我的代碼在基於視圖的應用程序中工作...但是當我使用tabbar時,它會被破壞......爲什麼? – Shahriar 2011-05-06 09:48:50

1

這意味着你有一些代碼試圖在UIViewController實例上調用createAddressBookCopy方法。根據documentation,沒有這樣的方法存在,因此崩潰。

1

這意味着,在你的程序的一些對象要發送createAddressBookCopy消息UIViewController,但這UIViewController對象沒有實現這樣的方法

+0

是的,我已經給出了代碼... – Shahriar 2011-05-06 09:47:07

1

UIViewController中沒有一個叫createAddressBookCopy方法。我懷疑你有一個UIViewController子類,它具有該方法,但出於某種原因,你正在調用超類。如果您使用的是界面構建器,並且沒有正確連接網點,則有時會發生這種情況。