繁体   English   中英

如何在执行segue之前如何获取UITableView中最后选择的行

[英]how to get the last selected row in a UITableView before a segue is executed

我在UITableView中插入了新行,现在我点击了另一个单元格(也通过调试器中的断点突出显示,此后,仅选择了被点击的行):

在此处输入图片说明

新行(UITextField)的文本为“ new”,所选单元格的标题为“ Hobby”

在现在选择的行/单元格“ Hobby”的点击上,我必须向另一个TableViewController(ColumnViewController)触发搜索

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if self.currentEdit != nil {
        self.currentEdit.resignFirstResponder()
    }
    if segue.identifier == "SetupColumn" {
        let cell = sender as! EditCell
        let destControlller = segue.destinationViewController as! ColumnViewController
        destControlller.kategorieID = cell.nameField.tag
    }
}

但是我必须知道,点击行/单元格“ Hobby”是因为我必须在调用segue之前弹出警报。 我只必须知道,该行与添加的行不同,而不是点击了哪一行。

self.currentEdit包含实际选择的TextField,但是我只是添加了一行。 :-(

更新

我得到了beyowulf的答案,您可以在下面看到。 我以为问题已经解决了,但是在玩了一段时间后,我突然(!?)得到了错误

应用程序由于未捕获的异常'NSInvalidArgumentException',原因:'Receiver()没有标识为'SetupColumn'的segue

beyowulf的答案是:

 Don't connect your segue to the your table view cells. Connect it to your view controller then call it explicitly when you want to segue

现在的问题是:我如何将segue连接到视图控制器,而不是将其连接到表视图单元

tableView.indexPathForSelectedRow是否提供您所需的内容?

要从视图控制器添加序列,请在其上单击鼠标右键,然后选择“触发的序列”,然后从“手动”行拖动到序列的目的地。

帮助其他和我一样愚蠢的人;-)

该解决方案在beyowulfMeriw水渠中 找到

我必须从我的SetUpViewController(源)和ColumnViewController(目标)中添加Manual Segue ,如屏幕截图所示 在此处输入图片说明

并将其命名为SetupColumn

在此处输入图片说明

然后我只需要添加

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.performSegueWithIdentifier("SetupColumn", sender:tableView.cellForRowAtIndexPath(indexPath))
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM