轻按细胞时,Uilabel向右移动



我有一个uibleview,其中包含单元格,我正在使用textLabel和deleteTextlabel以及一个cosceptoryView,这是一个披露indersionDindicator。这些是我的约束。

if (cell.contentView.constraints.count == 0) {
      cell.textLabel?.translatesAutoresizingMaskIntoConstraints = false
      cell.detailTextLabel?.translatesAutoresizingMaskIntoConstraints = false
      let margins = cell.contentView.layoutMarginsGuide
      // TextLabel constraints
      cell.textLabel?.leftAnchor.constraint(equalTo: margins.leftAnchor).isActive = true
      cell.textLabel?.centerYAnchor.constraint(equalTo: margins.centerYAnchor).isActive = true
      // DetailTextLabel constraints
      cell.detailTextLabel?.rightAnchor.constraint(equalTo: margins.rightAnchor, constant: -10).isActive = true
      cell.detailTextLabel?.leftAnchor.constraint(equalTo: (cell.textLabel?.layoutMarginsGuide.rightAnchor)!, constant: 10).isActive = true
      cell.detailTextLabel?.centerYAnchor.constraint(equalTo: margins.centerYAnchor).isActive = true
    }

现在,当首次加载表视图时,我看到一切都很好,即 detailTextLabel距离contentview是-10点,但是当我点击单元格时, detailTextLabel向右移动并拥抱到 contentView甚至在那里。现在,当我再次回到此VC时,我仍然看到detailTextLabel拥抱到ContentView,即reloadData没有任何效果。但是,如果我解散此VC,然后再次回到这里,我的约束和应有的限制,当我点击牢房进入下一个屏幕时,问题再次出现。

我在我的ViewWillAppear中有一个ReloDdata((调用,但不会产生任何效果。

我希望我能够解释自己,我在这里做错了吗?

问题是您使用的是内置的单元格类型,其中文本标签和细节标签是内置的,不属于您的。它们属于细胞。细胞重新定位它们。您正在与牢房作战。

如果要自定义单元格的外观并更改单元格标签的位置,请使用自定义单元格类型,并给它属于您的自定义标签。您可以在故事板设计师中给他们的约束。请勿完全使用内置文本标签和详细标签。

,如果单元格标签不是自定义类型单元格,则不能更改其约束。如果您需要自定义约束,则应创建自己的自定义单元格,该单元从UaiteViewCell继承并设置自己的约束。

最新更新