【问题标题】:How to change the UITableViewCell image on the left on the UIBarButtonItem?如何更改 UIBarButtonItem 左侧的 UITableViewCell 图像?
【发布时间】:2012-03-13 08:01:19
【问题描述】:

我是 iPhone 编程的新手。我陷入了困境。我需要通过从UIBarButtonItem 调用UIToolBar 的操作来更改UITableViewCell 图像(在左侧)。我已经通过互联网搜索,但找不到任何合适的解决方案。

对此的任何帮助将不胜感激。

【问题讨论】:

  • [cell.imageView setImage = [UIImage imageNamed:@""]];
  • 向我们展示代码和屏幕截图(如果可能)

标签: iphone objective-c uitableview xcode4.2 uibarbuttonitem


【解决方案1】:

这里是自定义单元格 imageView 的示例代码。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{        
    static NSString *CellIdentifier = @"MyTableViewCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                          reuseIdentifier:CellIdentifier];

      [cell.imageView setBounds:CGRectMake(0, 0, 30, 30)];
      [cell.imageView setClipsToBounds:YES];
      [cell.imageView setFrame:CGRectMake(0, 0, 30, 30)];

      [cell.imageView setContentMode:UIViewContentModeScaleAspectFit];
    }

    // customize cell
    [cell.imageView setImage:**your_image**];


    return cell;
}

【讨论】:

    【解决方案2】:

    使用 [tableview cellForRowAtIndexPath:] 方法,您可以访问特定行的单元格。当您访问它时,您可以通过 cell.imageView 访问图像。看看这个:

    - (IBAction)barbuttonPressed
    {
        UITableViewCell *cell = [self.tableView [NSIndexPath indexPathForRow:row inSection:section];
        cell.imageView = ..... 
    }
    

    用适当的替换行和部分。

    【讨论】:

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