Я создал ABAddressBook
на UITableView
. Теперь мне нужно передать firstname
, last name
и т. Д. В следующий диспетчер представлений.Как передавать данные между двумя контроллерами, в которых один контроллер является abadressbook, извлеченным в uitableviw
Мне нужно передать данные с помощью класса nsobject ... в этом проекте я создал класс Person, который имеет строковые свойства имени, имени, номера, адреса электронной почты.
Код для адресной книги:
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
allPeople = (__bridge NSMutableArray *)(ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonFirstNameProperty));
NSInteger numberOfPeople = [allPeople count];
for (NSUInteger i = 0; i < numberOfPeople; i++) {
personContact = [[Person alloc]init];
person = (__bridge ABRecordRef)allPeople[i];
NSString *firstName = (__bridge NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName = CFBridgingRelease(ABRecordCopyValue(person, kABPersonLastNameProperty));
if (firstName == nil) {
firstName = @"";
}
if (lastName == nil)
{
lastName = @"";
}
NSString *fullName = [NSString stringWithFormat:@"%@ %@",firstName,lastName];
personContact.firstName = firstName;
personContact.lastName = lastName;
personContact.fullName = fullName;
//For adding multiple contacts:
ABMultiValueRef phoneNumbers = ABRecordCopyValue((person), kABPersonPhoneProperty);
CFIndex numberOfPhoneNumbers = ABMultiValueGetCount(phoneNumbers);
for (CFIndex i = 0; i < numberOfPhoneNumbers; i++) {
NSString *phoneNumber = CFBridgingRelease(ABMultiValueCopyValueAtIndex(phoneNumbers, i));
if ([phoneNumber isEqualToString:@""])
{
phoneNumber = @"Not Available";
}
NSCharacterSet *trim = [NSCharacterSet characterSetWithCharactersInString:@"#();$&-+"];
phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet: trim] componentsJoinedByString: @""];
phoneNumber= [phoneNumber stringByReplacingOccurrencesOfString:@"\"" withString:@""];
phoneNumber=[phoneNumber stringByReplacingOccurrencesOfString:@"" withString:@""];
personContact.phoneNumber = phoneNumber;
//Emails
ABMutableMultiValueRef eMail = ABRecordCopyValue(person, kABPersonEmailProperty);
if(ABMultiValueGetCount(eMail) > 0)
{
email =CFBridgingRelease(ABMultiValueCopyValueAtIndex(eMail, 0));
}
else
{
email = @"";
}
personContact.email = email;
}
//Photos
CFDataRef imgData = ABPersonCopyImageData(person);
NSData *imageData = (__bridge NSData *)(imgData);
phoneImage = [UIImage imageWithData:imageData];
if (phoneImage == nil) {
phoneImage = [UIImage imageNamed:@"userEdit"];
}
CGSize destinationSize = CGSizeMake(70, 70);
UIGraphicsBeginImageContext(destinationSize);
[phoneImage drawInRect:CGRectMake(0, 0, destinationSize.width, destinationSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if (imgData != NULL)
{
CFRelease(imgData);
}
personContact.photos = (NSString *)newImage;
[contactsData addObject:personContact];
[contactstableView reloadData];
}
}
And the code for cellforrowatIndex path is as follows:-
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"CellID";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
cell.backgroundColor=[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:239.0/255.0 alpha:1.0];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
personContact = [searchResults objectAtIndex:indexPath.row];
}
else {
personContact = [contactsData objectAtIndex:indexPath.row];
}
if (contactsData.count > 0)
{
cell.textLabel.text = personContact.fullName;
cell.imageView.image = personContact.photos;
cell.imageView.layer.cornerRadius = 35;
cell.imageView.layer.masksToBounds = YES;
cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
}
На didselect
строки, я хочу передать все контактные данные на следующий регулятор. Пожалуйста помоги?
возможный дубликат [Передача данных между контроллерами View] (HTTP: // StackOverflow. com/questions/5210535/pass-data-between-view-controller) – mgyky
Мне нужна такая же реализация cellForRowAtIndexPAth, как этот пример http://www.appcoda.com/search-bar-tutorial-ios7/ –