簡體   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