Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何在没有segue的情况下将数据从UITableView传递到UIViewController_Swift_Uitableview_Uiviewcontroller - Fatal编程技术网

Swift 如何在没有segue的情况下将数据从UITableView传递到UIViewController

Swift 如何在没有segue的情况下将数据从UITableView传递到UIViewController,swift,uitableview,uiviewcontroller,Swift,Uitableview,Uiviewcontroller,我需要将UITableView中的行标题传递给我的ViewController。我在故事板中没有VC(我是通过代码创建的)。所以我不能用segue func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let cell = tableView.cellForRow(at: indexPath) as! UITableViewCell cell.textLabel?.tex

我需要将
UITableView
中的行标题传递给我的
ViewController
。我在故事板中没有VC(我是通过代码创建的)。所以我不能用segue

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

   let cell = tableView.cellForRow(at: indexPath) as! UITableViewCell


    cell.textLabel?.textColor = UIColor(red: 0, green: 122/255, blue: 1, alpha: 1)
    cell.textLabel?.tintColor = UIColor(red: 0, green: 122/255, blue: 1, alpha: 1)

        var titleOfFood = String()
        if searching == true {
           titleOfFood = searchedFoods[indexPath.row].title
            cell.textLabel?.textColor = UIColor(red: 0, green: 122/255, blue: 1, alpha: 1)
             print(titleOfFood)
        } else {
            titleOfFood = foods[indexPath.row].title
            cell.textLabel?.textColor = UIColor(red: 0, green: 122/255, blue: 1, alpha: 1)
             print(titleOfFood)
        }

    let controller = EatenFoodViewController()
    let transitionDelegate = SPStorkTransitioningDelegate()
    controller.transitioningDelegate = transitionDelegate
    controller.modalPresentationStyle = .custom
    //controller.delegate = self
    transitionDelegate.customHeight = 620
    transitionDelegate.showIndicator = false
    self.present(controller, animated: true, completion: nil)
}

我需要将
标题食品
传递给
EatenFoodViewController

您不需要一个序列就可以将数据发送到目标vc,您只需这样做即可

controller.titleOfFood = arr[indexPath.row].title // assuming you have an array of models 

controller.titleOfFood = cell.textLabel!.text!


如何从UITableView向TitleOfood行发送行标题,我无法理解var titleOfood=”“。这是什么。如何处理:)请参见编辑
var titleofood=“
是应该接收发送值的变量,您应该在目标vc中使用它
class EatenFoodViewController:UIViewController {
   var titleOfFood = ""
}