【问题标题】:How to create contact profile picture on UITableViewGrouped in iphone如何在 iphone 中分组的 UITableView 上创建联系人个人资料图片
【发布时间】:2011-07-25 20:30:44
【问题描述】:

目前,我在分组选项中有一个 UITableViewController。我正在尝试创建类似于地址簿 UI 的内容,其中包含个人资料联系人图片及其名称。 有没有办法在公司名称上方添加个人资料图片以及除了图片之外的人员姓名,如下图所示?任何示例或 Apple Book Reference 都会有所帮助。

【问题讨论】:

    标签: iphone objective-c uitableview uiview addressbookui


    【解决方案1】:
     - (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;
    

    我有你想创建像这张图片一样的通讯录然后使用这个代码。

    【讨论】:

      【解决方案2】:

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

      + (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 设置为联系人图片和联系人姓名即可。如果您需要进一步自定义,请尝试避免已经实现的样式并创建自己的样式。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-01-02
        • 2011-10-08
        • 1970-01-01
        • 1970-01-01
        • 2014-09-15
        • 2014-01-29
        • 1970-01-01
        相关资源
        最近更新 更多