0
連絡先をテーブルビューに追加するには、次のコードを使用してテーブルビューにすべての連絡先を追加することができますが、電話連絡先から選択した連絡先をテーブルに追加しますビュー。 いずれかが..あなたは、あなたが連絡先を反復しようとしているどのような条件に指定されていませんでした.....次のコードを変更する方法iphone連絡先から連絡先をテーブルビューに追加
-(void)loadTableSource{
contactsToBeAdded=[[NSMutableArray alloc] init];
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
//CFArrayRef people = ABAddressBookCopyPeopleWithName(addressBook,CFSTR("Rajesh"));
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
for(int i=0;i<nPeople;i++){
ABRecordRef person=CFArrayGetValueAtIndex(people, i);
NSString *firstName=(NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName=(NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString *organization=(NSString *)ABRecordCopyValue(person, kABPersonOrganizationProperty);
if(!firstName) [email protected]"";
if(!lastName) [email protected]"";
if(!organization) [email protected]"";
NSDictionary *curContact=[NSDictionary dictionaryWithObjectsAndKeys:(NSString *)firstName,@"firstName",lastName,@"lastName",organization,@"organization",nil];
[contactsToBeAdded addObject:curContact];
}
CFRelease(people);
CFRelease(addressBook);
[self setTableSource:contactsToBeAdded];
[contactsToBeAdded release];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdent=[NSString stringWithFormat:@"c%i",indexPath.row];
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdent];
if(cell==nil){
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdent];
NSDictionary *dict=[tableSource objectAtIndex:indexPath.row];
UILabel *lab=[[UILabel alloc] initWithFrame:CGRectMake(5, 5, 310, 40)];
NSLog(@"lable:%@",tableSource);
[lab setNumberOfLines:2];
[lab setText:[[NSString stringWithFormat:@"%@ %@\n%@",(NSString *)[dict objectForKey:@"firstName"],[dict objectForKey:@"last_name"],[dict objectForKey:@"organization"]] stringByReplacingOccurrencesOfString:@"(null)" withString:@""]];
[cell.contentView addSubview:lab];
[lab release];
}
return cell;
}
ありがとう、私は特定の連絡先を追加したいと思うのは、連絡先(名前)をクリックしてその連絡先だけを自分のテーブルのセルに追加することです。 – user564963