繁体   English   中英

如何在iPhone中的UITableViewGrouped上创建联系人个人资料图片

[英]How to create contact profile picture on UITableViewGrouped in iphone

目前,我在分组选项中有一个UITableViewController。 我正在尝试创建类似于通讯录UI的东西,该UI带有个人档案联系人图片及其名称。 有没有一种方法可以在公司名称上方添加个人资料图片,并按照下面的图片在人物姓名之外添加个人姓名? 任何示例或Apple Book Reference都会有帮助。

在此处输入图片说明

 - (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;

在此处输入图片说明

我要创建像这样的地址簿,然后使用此代码。

获取联系人姓名和图像的代码如下

+ (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;
}

至于单元格,只需将cell.imageView.image和cell.textLabel.text设置为联系人图像和联系人姓名即可。 如果需要进一步的自定义,请尝试避免使用已经实现的样式并创建自己的样式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM