Swift2 在Swift中使用UIAlertAction在视图控制器之间传递数据

Swift2 在Swift中使用UIAlertAction在视图控制器之间传递数据,swift2,Swift2,我有一个tableView,当用户点击一个单元格时,它会打开一个带有“关闭”和“搜索”选项的警报框。“搜索”的处理程序如下所示func searchSongAction 这将提供一个新的viewcontroller(嵌入导航栏中),用于在线搜索歌曲。在这个新的viewcontroller中,Search,有两个功能:一个搜索当前播放的歌曲,另一个搜索用户要求从tableView警报中搜索的歌曲 我试图将数据从单元格传递到搜索类中,但我一直做得不够。我觉得我所说的是对的,但显然不是这样 有什么想法

我有一个tableView,当用户点击一个单元格时,它会打开一个带有“关闭”和“搜索”选项的警报框。“搜索”的处理程序如下所示
func searchSongAction

这将提供一个新的viewcontroller(嵌入导航栏中),用于在线搜索歌曲。在这个新的viewcontroller中,
Search
,有两个功能:一个搜索当前播放的歌曲,另一个搜索用户要求从tableView警报中搜索的歌曲

我试图将数据从单元格传递到搜索类中,但我一直做得不够。我觉得我所说的是对的,但显然不是这样

有什么想法吗

问我你是否需要更多的信息

史威夫特

搜索,斯威夫特


您实际上没有执行
searchSongAction:
函数中的一个序列,因此我猜
prepareforsgue:sender:
实际上没有被调用,因此安装程序没有运行

尝试在
vc
searchSongAction:
内部分配
searchType
songNowText
artistNowText

func searchSongAction(alert: UIAlertAction!) {
    let vc = self.storyboard?.instantiateViewControllerWithIdentifier("Search") as! Search

    //Setup the properties
    vc.searchType = "Previous"
    vc.songNowText = self.songToSearch
    vc.artistNowText = self.artistToSearch

    let navigationController = UINavigationController(rootViewController: vc)
    self.presentViewController(navigationController, animated: true, completion: nil)
}

作为旁注,通常在重写函数时,您需要调用函数的
super
(您在
prepareforsgue:sender:
中忽略了这一点)

好的,这是有意义的。我没有想到我没有打电话给预备队员。谢谢。
class Search: UIViewController {

var songNowText = ""
var artistNowText = ""
var searchType = ""

override func viewDidLoad() {
    super.viewDidLoad()

    if searchType == "Previous" {
        searchSongPrevious()
    } else {
        searchSongNow()
    }

}
}
func searchSongAction(alert: UIAlertAction!) {
    let vc = self.storyboard?.instantiateViewControllerWithIdentifier("Search") as! Search

    //Setup the properties
    vc.searchType = "Previous"
    vc.songNowText = self.songToSearch
    vc.artistNowText = self.artistToSearch

    let navigationController = UINavigationController(rootViewController: vc)
    self.presentViewController(navigationController, animated: true, completion: nil)
}