0

現在、グループ化されたオプションにUITableViewControllerがあります。プロフィールの連絡先画像とその名前が隣接しているアドレス帳UIに似たものを作成しようとしています。下の画像のように、会社名の上にプロフィール写真を追加し、写真のほかに人の名前を追加する方法はありますか?任意の例またはAppleBookReferenceが役立ちます。

ここに画像の説明を入力してください

4

2 に答える 2

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;

ここに画像の説明を入力

この画像のようなアドレス帳を作成したいので、このコードを使用します。

于 2011-07-26T06:28:32.853 に答える
0

連絡先の名前と画像を取得するコードは次のとおりです。

+ (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 を設定するだけです。さらにカスタマイズが必要な場合は、既に実装されているスタイルを避けて、独自のスタイルを作成してください。

于 2011-07-26T06:30:03.557 に答える