【发布时间】: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 here 和 here 中。我无法评论这些问题本身是否已解决,因为我没有所需的声誉。 正如这些问题中提到的 -
- 我在 Storyboard 中使用了 UITableViewController,所以我没有手动添加任何约束。
- 我尝试使用here 提到的sourceRect,但无济于事。
另外,我在实际设备上运行应用程序时遇到了错误。模拟器没有报错。
有人可以帮我解决这个错误吗?或者这个问题是已知的并且没有解决?谢谢!
【问题讨论】:
-
每当我尝试显示共享表时,我都会在控制台中遇到相同的错误...似乎是 iOS 错误。
-
FWIW 我也看到了同样的错误。我还没有找到任何解决方法。
标签: swift ios13 uiactivityviewcontroller