【问题标题】:Why is UIActivityViewController displaying auto constraint errors in console为什么 UIActivityViewController 在控制台中显示自动约束错误
【发布时间】:2019-11-18 09:11:01
【问题描述】:

我正在尝试使用 UIActivityViewController 实现共享功能。使用 Swift 5、Xcode 11.2.1、ios 13.2。

我使用了 UITableViewController 并在行的单击中调用了 share() 方法,如下所示:

class SettingsTableViewController: UITableViewController {

    var tableData = ["Share with friends"]

    // MARK: - Table view methods
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return tableData.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "settingsCell", for: indexPath)
        let row = indexPath.row
        cell.textLabel?.text = tableData[row]
        return cell
    }

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        share()
    }

    func share() {
        print("Share with friends")
        let items: [Any] = ["This app is my favorite", URL(string: "https://www.apple.com")!]
        let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
        self.present(ac, animated: true)

    }
}

单击“与朋友分享”行时出现以下错误。奇怪的是,错误并不总是发生。

2019-11-18 14:28:23.951523+0530 ShareSheetDemo[425:18210] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x282b740f0 _UIActivityActionCellTitleLabel:0x11fd94510.height >= 22   (active)>",
    "<NSLayoutConstraint:0x282b692c0 V:|-(15)-[_UIActivityActionCellTitleLabel:0x11fd94510]   (active, names: '|':UIView:0x11fd92fb0 )>",
    "<NSLayoutConstraint:0x282b69540 V:[_UIActivityActionCellTitleLabel:0x11fd94510]-(15)-|   (active, names: '|':UIView:0x11fd92fb0 )>",
    "<NSLayoutConstraint:0x282b74280 'UIView-Encapsulated-Layout-Height' UIView:0x11fd92fb0.height == 50.5   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x282b740f0 _UIActivityActionCellTitleLabel:0x11fd94510.height >= 22   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-11-18 14:28:25.925309+0530 ShareSheetDemo[425:18241] [ShareSheet] connection invalidated

我发现错误出现在 iOS 9 herehere 中。我无法评论这些问题本身是否已解决,因为我没有所需的声誉。 正如这些问题中提到的 -

  1. 我在 Storyboard 中使用了 UITableViewController,所以我没有手动添加任何约束。
  2. 我尝试使用here 提到的sourceRect,但无济于事。

另外,我在实际设备上运行应用程序时遇到了错误。模拟器没有报错。

有人可以帮我解决这个错误吗?或者这个问题是已知的并且没有解决?谢谢!

【问题讨论】:

  • 每当我尝试显示共享表时,我都会在控制台中遇到相同的错误...似乎是 iOS 错误。
  • FWIW 我也看到了同样的错误。我还没有找到任何解决方法。

标签: swift ios13 uiactivityviewcontroller


【解决方案1】:

这是 Apple 的错误,不是你的。忽略控制台消息并继续。

【讨论】:

    【解决方案2】:

    我不知道这是否对您有用,但我们团队中的其他一位工程师发现将 present(_:animated:) 调用包装在调度块中似乎可以解决问题(至少在我们的应用程序中)。

    DispatchQueue.main.async {
        self.present(controller, animated: true)
    }
    

    【讨论】:

    • 只为我工作了一部分。错误消息较少,但仍有一些。我会忽略它们。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-05
    • 2018-05-31
    • 2012-06-07
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    相关资源
    最近更新 更多