当我从我的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
没有分配和任何对象的初始化。
- ios设置UISlider的开始位置和增量
- 当试图在实际的Apple Watch上构build和运行WatchKit扩展时,如何避免“Error Launching”AppName“WatchKit Extension”错误?
- 嵌套的UIScrollViews。 尝试让其中一个以与另一个放大速度相同的速度和因子缩小。视图冻结
- iOS9 Sprite Kit问题
- 在具有.xib文件的项目中使用故事板 – iPhone
- contentsize和contentOffset等同于NSScroll视图
- 如何将定向数据写入UIImage iOS SDK
- 有没有办法改变一个UILabel的textAlignmentanimation?
- prefersStatusBarHidden不会被调用