【问题标题】:UIImage in TableViewCell pushes Cell SeparatorTableViewCell 中的 UIImage 推送单元格分隔符
【发布时间】:2014-02-16 20:26:56
【问题描述】:

我已将 UIImage 添加到我的表格视图单元格中。但是,UIImage 将分隔符推到右侧,以便为 UIImage 腾出空间。我想找到一种方法让分隔符包含 UIImage 而不会被推过去。这是我的表格视图单元格的图片。

这是我的 cellForRowAtIndexPath 方法和图像代码:

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

    UITableViewCell *cell =
    [tableView dequeueReusableCellWithIdentifier:CellIdentifier
                                forIndexPath:indexPath];

   Exercise *tempPlaceholder = [exercisesInTable objectAtIndex:indexPath.row];



   NSString *exerciseDisplayName = tempPlaceholder.exerciseName;

   exerciseDisplayName = [exerciseDisplayName capitalizedString];

    exerciseDisplayName =
   [exerciseDisplayName  stringByReplacingOccurrencesOfString:@"_"
                                                withString:@" "];

   cell.textLabel.text = exerciseDisplayName;

   cell.imageView.image = [UIImage imageNamed:@"quads.png"];


    return cell;
}

如果有人能帮我解决这个问题,我将不胜感激。谢谢。

【问题讨论】:

标签: ios objective-c uitableview


【解决方案1】:

对于遇到此问题的其他人,使用:

[self.tableView setSeparatorInset:UIEdgeInsetsZero];

将填补 UIImage 和表格单元格分隔符之间的空白。

【讨论】:

    【解决方案2】:

    尝试改变 imageView 框架的大小

    cell.imageView.frame = CGRectMake(0, 0, 10.0, 10.0);
    

    或者改变单元格的高度

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
      return 40.0;
    }
    

    【讨论】:

      【解决方案3】:

      您遇到的行为只会发生在 iOS 7 上,其中分隔符具有默认情况下随图像视图大小而变化的插图。

      要删除此行为,只需将分隔符插入设置为零。但是,separatorInset 属性在 iOS 7.0

      UITableView 上可用

      所以你只需要在 iOS 7 中删除插图。

      可以查看表格视图是否响应setSeparatorInset:doing

      if ([self.tableview respondsToSelector:@selector(setSeparatorInset:)]) 
      {
          [self.tableview setSeparatorInset:UIEdgeInsetsZero];
      }
      

      【讨论】:

        猜你喜欢
        • 2016-08-25
        • 1970-01-01
        • 1970-01-01
        • 2013-08-14
        • 1970-01-01
        • 2011-02-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多