我试图将数据从我的UITableView传递到UIViewController以显示更多详细信息。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        if segue.identifier == "PassDetail" {

            let vc = segue.destinationViewController as! ToDoListDetailViewController
            let customIndexPath = self.tableView.indexPathForSelectedRow
            vc.titleString = userList[userList.count - customIndexPath!.row - 1].Title
            vc.descriptionString = userList[userList.count - customIndexPath!.row - 1].Description

        }

    }

我创建了一个segue push depricated并设置了适当的标识符。

运行后,什么都没有发生。不会崩溃,我尝试设置了创建打印方法,但是当我点击一个单元格时什么也没叫。

我试图查看字符串中是否包含要与打印语句一起传递的值,但没有收到打印语句的回音。

即使没有任何数据,当我点击一个单元格时,该应用程序至少也应该崩溃。但事实并非如此。

我尝试使用show和东西等不同的标记,但这并不能解决问题。

我的代码中缺少什么吗?

解决方案

我找到了解决方案。

这就是我了解其工作原理的方式。
我上面的代码传递数据,但不会推送到下一个ViewController。

为了解决这个问题,我使用了didelectRowAtIndexPath方法并设置了我的字符串。

以下是我的完整工作代码。

覆盖func tableView(tableView:UITableView,didSelectRowAtIndexPath indexPath:NSIndexPath){
    contentTitle = "Some title" //contentTitle is a global variable

    tableView.deselectRowAtIndexPath(indexPath, animated: true)
    let row = indexPath.row
    performSegueWithIdentifier("PassData", sender: row)

}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if segue.identifier == "PassData" {

        let vc = segue.destinationViewController as! ToDoListDetailViewController
        vc.titleString = contentTitle //setting the titleString created from my ToDoListDetailViewController and setting it to contentTitle

    }

}

最佳答案

从我的怀疑来看,您还没有以编程方式推动您的搜索。

here获取提示,您是否从didSelectRowAtIndexPath方法中推送了segue?

关于ios - 将带有序列的数据从UITableView传递到UIViewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38545239/

10-12 15:57
查看更多