当我从我的tableviewselect一些选定的用户,它显示(空)

当我从我的tableviewselect一些选定的用户显示(空)。

-(void)retriveContactsFromAddressBook { //CFErrorRef error = NULL; ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL); //self.phoneNumber=[NSMutableArray arrayWithObject:@" "]; if (addressBook!=nil) { NSArray *allContacts=(__bridge_transfer NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook); NSUInteger i=0; for ( i = 0; i<[allContacts count]; i++) { ABRecordRef contactPerson = (__bridge ABRecordRef)allContacts[i]; NSString *firstName = (__bridge_transfer NSString*)ABRecordCopyValue(contactPerson, kABPersonFirstNameProperty); NSString *lastName=(__bridge_transfer NSString*)ABRecordCopyValue(contactPerson, kABPersonLastNameProperty); if (i==0) { self.FirstName=[NSMutableArray arrayWithObject:firstName]; if (lastName==nil) { self.LastName=[NSMutableArray arrayWithObject:@""]; } else { self.LastName=[NSMutableArray arrayWithObject:lastName]; } } else { [self.FirstName addObject:firstName]; if (lastName==nil) { [self.LastName addObject:@""]; } else { [self.LastName addObject:lastName]; } } NSString *full=[NSString stringWithFormat:@"%@ %@",[self.FirstName objectAtIndex:i],[self.LastName objectAtIndex:i]]; if (i==0) { self.fullName=[NSMutableArray arrayWithObject:full]; } else { [self.fullName addObject:full]; } } } else { NSLog(@"Error Address book empty"); } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:indexPath]; tableViewCell.accessoryType=UITableViewCellAccessoryCheckmark; tableViewCell.accessoryView.hidden = YES; self.selectedUsers=[[NSMutableArray alloc]initWithObjects:self.phoneNumber[indexPath.row],nil]; NSLog(@"selected users:%@",self.phoneNumber); 

错误显示Bellow:

 selected users:(null) 

 -(void)retriveContactsFromAddressBook { //CFErrorRef error = NULL; ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL); self.phoneNumber=[NSMutableArray array]; self.FirstName=[NSMutableArray array]; self.fullName=[NSMutableArray array]; self.LastName=[NSMutableArray array]; if (addressBook!=nil) { NSArray *allContacts=(__bridge_transfer NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook); NSUInteger i=0; for ( i = 0; i<[allContacts count]; i++) { ABRecordRef contactPerson = (__bridge ABRecordRef)allContacts[i]; ABMultiValueRef phones =(__bridge ABMultiValueRef)((__bridge NSString*)ABRecordCopyValue(contactPerson, kABPersonPhoneProperty)); if (ABMultiValueGetCount(phones) == 0) break; NSString* mobileLabel; for(CFIndex i = 0; i < ABMultiValueGetCount(phones); i++) { mobileLabel = (__bridge NSString*)ABMultiValueCopyLabelAtIndex(phones, i); if ([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel]) { NSString *phoneNumber = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phones, i); if(phoneNumber.length > 0) { [self.phoneNumber addObject:phoneNumber]; break; } } } NSString *firstName = (__bridge_transfer NSString*)ABRecordCopyValue(contactPerson, kABPersonFirstNameProperty); NSString *lastName=(__bridge_transfer NSString*)ABRecordCopyValue(contactPerson, kABPersonLastNameProperty); [self.FirstName addObject:firstName]; if (lastName==nil) { [self.LastName addObject:@""]; } else { [self.LastName addObject:lastName]; } NSString *full=[NSString stringWithFormat:@"%@ %@",[self.FirstName objectAtIndex:i],[self.LastName objectAtIndex:i]]; [self.fullName addObject:full]; } } else { NSLog(@"Error Address book empty"); } } 

初始化self.selectedUsers = [NSMutableArray array]; 这在viewDidLoad中

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init]; if([MFMessageComposeViewController canSendText]) { picker.messageComposeDelegate = self; picker.recipients = @[self.phoneNumber[indexPath.row]]; [self presentViewController:picker animated:YES completion:nil]; } } 

我更新我的代码

包括支持消息的MessageUI框架

NSLog(@"selected users:%@",self.phoneNumber); 应该loggingnil因为self.phoneNumber没有分配和任何对象的初始化。