0

Currently, I have a UITableViewController in grouped option. I am trying to create something similar to Address Book UI which has profile contact picture and its name adjacent to it. Is there a way to add a profile picture above the company name and the name of the person besides the picture as per the image below? Any example or Apple Book Reference will be helpful.

enter image description here

lifemoveson
  • 1,621
  • 7
  • 25
  • 54

2 Answers2

0
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

// Create
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    //cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

}

// Configure
switch (indexPath.row) {
    case 0: 
        cell.textLabel.text = @"                Evolutions";
        cell.backgroundColor=[UIColor clearColor];
        cell.textLabel.textColor=[UIColor whiteColor];
        CGRect myImageRect =CGRectMake(20,10,75,80);
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:myImageRect];
        [imageView setImage:[UIImage imageNamed:@"page-1.jpg"]];
        [cell addSubview :imageView];
        [imageView release]; 

        UIButton *btnView= [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [btnView addTarget:self action:@selector(View:)forControlEvents:UIControlEventTouchDown];
        [btnView setTitle:@"View" forState:UIControlStateNormal];
        [btnView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btnView.frame=CGRectMake(235,36, 72,30 );

        [ cell addSubview: btnView];
        break;

enter image description here

i have u want to create address book like this image then use this code.

ram
  • 1,191
  • 1
  • 15
  • 27
0

The code to get the name and the image of the contacts is as follow

+ (NSMutableArray *) getAllContacts {

  // Fetch the address book 
    ABAddressBookRef addressBook = ABAddressBookCreate();
   NSArray *people = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
  NSMutableArray *contacts = [NSMutableArray array];

  for (CFIndex i = 0; i < [people count]; i++) {

    ABRecordRef record = [[people objectAtIndex:i] retain];
    NSString *fullname =(NSString *)ABRecordCopyCompositeName(record); 
    NSMutableDictionary *dict = [NSMutableDictionary dictionary] ;
    if (![contacts containsObject:fullname]) {
      [dict setValue:fullname forKey:@"name"];
      changes = YES;
    }
    if (ABPersonHasImageData(record)) {
      UIImage *image = [UIImage imageWithData:(NSData *)ABPersonCopyImageData(record)];
      [dict setObject:image forKey:@"image"];
      changes = YES;
    }

    CFRelease(record);
    [fullname release];
  }
  CFRelease(addressBook);
  [people release];

  return contacts;
}

As for the cell, just set the cell.imageView.image and cell.textLabel.text as the contact image and contact name. If you need further customization, try avoiding already implemented styles and create your own.

Yorxxx
  • 579
  • 2
  • 4