【问题标题】:Way to change icon of accessory type in UITableviewcell在 UITableviewcell 中更改附件类型图标的方法
【发布时间】:2011-06-01 06:44:32
【问题描述】:

我有一个表格视图,它显示了要下载的文件列表。当我点击附件按钮时,它将下载所选文件。我想更改详细信息披露按钮的图像。有没有可能……?

如果我在附件视图中使用带有图像的按钮。是否有任何表委托方法...

【问题讨论】:

    标签: iphone uitableview accessoryview


    【解决方案1】:

    Answer2:在这种情况下,您可以创建自己的方法并调用它。

    int row=indexPath.row;
    
    UIButton *trackImageOnMap=[[UIButton alloc] initWithFrame:CGRectMake(420, 9, 40, 50)];
    [trackImageOnMap setImage:[UIImage imageNamed:@"track_map_icon.png"] forState:UIControlStateNormal];
    int iId=[[self.imageId objectAtIndex:row] intValue];
    NSLog(@"iId=%d",iId);
    [trackImageOnMap setTag:iId];
    [trackImageOnMap addTarget:self action:@selector(trackImageOnMapButtonTouched:)forControlEvents:UIControlEventTouchDown];
    [trackImageOnMap setContentMode:UIViewContentModeScaleToFill];
    //[cell setAccessoryView:trackImageOnMap];
    [cell addSubview:trackImageOnMap];
    

    【讨论】:

    • NSString *file = [NSString stringWithFormat:@"/%@",[metaArray objectAtIndex:indexPath.row]];我怎样才能得到数组的indexpath.row
    • 当您在该单元格上设置该按钮时,您不需要制作按钮的标签。然后该按钮的标签将成为您的索引路径。:)
    • button.tag = cell.indexPath is given error request for member indexpath is something not a structure or union
    • @pallavi: 试试这个,[cell addSubview:button];
    • ya..但是我设置了它的 x 坐标并且 cell.accssoryview = 按钮工作完美
    【解决方案2】:

    您可以创建一个 UIImageView 并将其分配给 UITableViewCell 的附件视图。

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

    如果你想要一个附件视图的按钮,它基本上是一样的:

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"buttonImage"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(someAction:) forControlEvents:UIControlEventTouchUpInside];
    button.tag = cell.indexPath;
    cell.accessoryView = button;
    

    【讨论】:

    • 我可以使用 NSString *file = [NSString stringWithFormat:@"/%@",[metaArray button.tag]]???
    • button.tag = cell.indexPath is given error request for member indexpath is something not a structure or union
    • button.tag = indexPath.row 正在崩溃
    【解决方案3】:

    如果要替换默认类型,可以覆盖 UITableViewCell 并使用以下代码:

    - (void)setAccessoryType:(UITableViewCellAccessoryType)accessoryType
    {
        if (accessoryType == UITableViewCellAccessoryDisclosureIndicator)
        {
            self.accessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YourNewImage.png"]] autorelease];
        }
        else
        {
            [super setAccessoryType:accessoryType];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多