【问题标题】:Issue at resizing TableViewCell and UIImageView调整 TableViewCell 和 UIImageView 大小时的问题
【发布时间】:2013-01-10 04:29:03
【问题描述】:

我有一个带有自定义单元格的 TableView。每个单元格显示一个 300 像素大的 UIImageView(并非所有图像都具有相同的尺寸)。 然后我使用宽高比来动态获取新的高度。

此时,我调整了 UIImageView 和 TableViewCell 的大小:

// In -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
// Resize my UIIMageView
cell.myImage.frame = CGRectMake(10, 10, 300, newHeight);

// In -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
return newHeight;

但我遇到了一些奇怪的事情,一些图像超出了它们的单元格扩展到其他单元格。 有什么我错过或做错了吗? 感谢您的帮助。

【问题讨论】:

  • 你是如何解决这个问题的?我遇到了同样的问题。
  • 如果你想动态地做这个有点复杂。我很抱歉,但我不记得我是如何解决这个问题的。祝你好运!

标签: ios uitableview uiimageview dimensions


【解决方案1】:

像这样在(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath"中简单地return new height

(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 90;
}

【讨论】: