【问题标题】:Resize UITableViewCell to show image at maximum size调整 UITableViewCell 的大小以以最大尺寸显示图像
【发布时间】:2011-03-05 16:24:34
【问题描述】:

我想在 UITableView 中显示一些图像和文本。

但是当我将图像添加到它的 UITableViewCell 时,它会破坏布局并与下一个 Header 重叠。

如何设置包含图像的单元格的大小,以免布局被破坏?

我发现一些 ObjC 代码表明可以使用 heightForRowAtIndexPath 来完成,但我找不到任何 MonoTouch 特定的内容。

【问题讨论】:

    标签: iphone xamarin.ios


    【解决方案1】:
    class TableDelegate : UITableViewDelegate {
    
          public override float GetHeightForRow (UITableView tableView, NSIndexPath indexPath)
            {
                // return 50f;
                                //set your cell height;
            }
    
        }
    

    【讨论】:

      【解决方案2】:

      看看这个blog post。它会为文本动态调整表格单元格的大小,但您可以将其应用于您的图像。

      【讨论】:

      • 谢谢,这很有帮助。基本上它归结为继承您自己的 UITableViewDelegate 并将其用于您的 UITableView 以便您通过 GetHeightForRow 询问每行的高度。
      • 我又试了一次,它对我有用。如果您遇到问题,可以随时尝试google cache 版本。
      【解决方案3】:

      如果所有单元格的高度相同,请设置UITableViewrowHeight 属性。否则,使用UITableViewDelegate 方法:

      - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
      

      这就是你在 CocoaTouch/Obj-C 中所做的。我不知道如何将原生 Obj-C 转换为可以在 MonoTouch 中使用的东西。祝你好运。 :-)

      【讨论】:

        猜你喜欢
        • 2012-12-16
        • 2015-03-12
        • 2011-09-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-27
        • 2019-06-12
        相关资源
        最近更新 更多