0

我的理解是,要显示带有图像的附件视图,您需要更改 cellForRowWithIndex 路径。

基于 SO 中的各种教程和问题,我将除了厨房水槽之外的所有东西都投入了这种方法。有人说你只需要包含附件视图。其他人说你需要一个按钮。无论如何,图像仍然没有显示。

我还被告知该问题不在情节提要中,因为在库存附件视图之一中与没有。

任何人都可以推荐一种确保图像显示在附件视图中的方法:

这是我一直在尝试但没有成功的方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
   // UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//    cell.selectionStyle = UITableViewCellSelectionStyleBlue;

    IDContactImport *contactImport = self.contacts[indexPath.row];
    IDTableViewCell *idTableCell =(IDTableViewCell *)cell;
    idTableCell.contactImport=contactImport;
    if (contactImport.imageData==nil)
    {
        idTableCell.iconView.image = [UIImage imageNamed:@"headshot.jpg"];
    }
    else{
       idTableCell.iconView.image = [UIImage imageWithData:contactImport.imageData];
    }
    UIImage *image = [UIImage imageNamed:@"checked.gif"];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
    button.frame = frame;
    [button setBackgroundImage:image forState:UIControlStateNormal];

    [button addTarget:self action:@selector(checkButtonTapped:event:)  forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = [UIColor clearColor];
    cell.accessoryView = button;


    NSLog(@"Trying to load accessory image");

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checked.gif"]];
    cell.accessoryView = imageView;
  //  UIImage *image = [UIImage   imageNamed:@"headshot.jpg"];

 //   UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
 //   CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
    button.frame = frame;
    [button setBackgroundImage:image forState:UIControlStateNormal];

    [button addTarget:self action:@selector(checkButtonTapped:event:)  forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = [UIColor clearColor];
    cell.accessoryView = button;
    return cell;
}
4

1 回答 1

0

你那里有正确的答案。但它后来在代码中被破坏了。

这是对的:

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checked.gif"]];
cell.accessoryView = imageView;

此外,使用 PNG 图像,而不是 GIF。对于 iOS 开发来说,这是一种更好的格式。

于 2015-06-11T01:11:51.857 回答