【问题标题】:Swift :How can i remove the outlets from code?斯威夫特:我怎样才能从代码中删除出口?
【发布时间】:2017-10-05 05:25:05
【问题描述】:

我有一个观景高度出口。它设置为 55。在 tableview 中我使用过它。有些地方我需要静态高度,有些地方不需要高度。所以我想从我的代码中删除这个静态高度。我怎样才能做到这一点?有可能吗?

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        if(heightIsStatic.count> 0)
        {
     //here i require a static height and is working fine as height can   
     //be printed as 55
        }
        else
        {
            self.ViewHeight.active = false
            print(self.ViewHeight.constant)
        }
    }

即使我已将 active 设置为 false,它仍然显示静态高度限制。在其他情况下我可以删除该静态高度吗??

【问题讨论】:

  • ViewHeight.constant = 65 //StaticValue 这样做。
  • 我知道吗?我在问如何删除此约束,使其不适用于其他条件。
  • 要了解更多问题,您可以给我看一下您的屏幕图像吗?
  • 如果你不想要高度,那么在其他条件下使用ViewHeight.constant = 0
  • 即使在其他情况下高度仍然显示 55。这就是我的全部问题,我想以任何方式将其删除。

标签: ios uitableview swift2


【解决方案1】:

如果你想要 else 部分的动态大小,那么你必须删除约束的出口,然后在你的代码中你必须找到约束,然后将其更改为常量或在需要时删除

for constraint in view.constraints {
    if(constraint.firstAttribute == NSLayoutAttribute.height)
    {
         constraint.constant = 55
    }
}

【讨论】:

  • 无法分配属性。关系是仅获取属性..?
  • @jennysam 解决了你的问题吗?如果您遇到任何问题,请告知。
  • 谢谢@Varun 真的很喜欢你的把戏 :) :) :)。抱歉回复晚了
【解决方案2】:

如果我正确理解了你的问题,请试试这个(假设你的单元格的约束是正确的)

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
 if (indexPath.row == 1) { //change this with the row number
  return 55.0
 }

 return UITableViewAutomaticDimension
}

如果您没有特定的行,请发表评论,我将编辑我的答案。谢谢!

【讨论】:

  • 这实际上不是我要问的 :) :) :) 它与特定行无关
猜你喜欢
  • 1970-01-01
  • 2023-03-19
  • 1970-01-01
  • 1970-01-01
  • 2017-07-22
  • 2017-03-24
  • 1970-01-01
  • 2018-10-12
  • 1970-01-01
相关资源
最近更新 更多