gpt4 book ai didi

ios - Swift 3 indexPathForSelectedRow - 获取空路径

转载 作者:行者123 更新时间:2023-11-28 06:15:28 28 4
gpt4 key购买 nike

我正在尝试调整 segue 中弹出 View 的大小。弹出窗口有效,但位置错误。

为了设置位置,我使用以下代码尝试选择当前的 IndexPathForSelectedRow,然后设置弹出值。

它没有触发,我需要一些帮助来找出原因。

我使用的代码如下:

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

if segue.identifier == "RecordToNotes" {

if let path = detailsTable.indexPathForSelectedRow {
let cellFrame = detailsTable.rectForRow(at: path)

let vc = segue.destination
vc.preferredContentSize = CGSize(width: 400, height: 400)
let controller = vc.popoverPresentationController
controller?.delegate = self
controller?.sourceView = detailsTable
controller?.sourceRect = CGRect(x: cellFrame.midX + 50, y: cellFrame.midY, width: 0, height: 0)
controller?.permittedArrowDirections = .right
}

}

}

路径返回nil。感谢您的帮助。

更新:我在 cellAtRow 中设置了单元格。这是该片段:

case 2: //notes
cell.detailPickerButton.isHidden = false
cell.detailPickerButton.isEnabled = true

cell.detailPickerButton.addTarget(self, action: #selector(detailsViewController.showNotesPanel(_:)), for: UIControlEvents.touchUpInside)
....

我没有覆盖 didSelectRow。我应该吗?

最佳答案

尝试将框架转换为您的 ViewController.View 坐标

使用这条线

controller?.sourceRect = self.view.convert(cellFrame, from: detailsTable)

代替

controller?.sourceRect = CGRect(x: cellFrame.midX + 50, y: cellFrame.midY, width: 0, height: 0)

希望对你有帮助

关于ios - Swift 3 indexPathForSelectedRow - 获取空路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45267424/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com