在Swift中传递没有视图转换的数据

时间:2016-10-12 10:05:55

标签: swift uitableview

我通过UITableView连接了两个segue。我正在执行segue使用tableViewCell滑动操作方法将数据从firstTableView传递到secondTableView,并使用NSUserDefaults代码保存传递的数据。但是,每当我传递数据时,它调用segue(我知道它应该)并推送到我的secondTableView ..我想传递数据而不会在传递数据时将我的firstTableView推送到secondTableView并且我有操作按钮来访问我的secondController直接来自mainViewController。

func tableView(_ tableView: UITableView, editActionsForRowAtIndexPath indexPath: IndexPath) -> [UITableViewRowAction]? {


    let shareAction = UITableViewRowAction(style: UITableViewRowActionStyle.normal, title: "xxxxxxxxxx") { (UITableViewRowAction, NSIndexPath) -> Void in

        self.performSegue(withIdentifier: "shareSegue", sender: indexPath)

        //   self.dismiss(animated: true, completion: nil)
    }

    return shareAction 
    }


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

    if (segue.identifier == "shareSegue") {

        // initialize new view controller and cast it as your view controller
        let viewController = segue.destination as! ViewController
        // your new view controller should have property that will store passed value
        viewController.labelcell = (sendSelectedData as String as String)

         }

      //// I also tried the following method with no segue but the results pretty much same....
       let storyboard = UIStoryboard(name: "Main", bundle: nil)
       let secondVC = storyboard.instantiateViewControllerWithIdentifier("secondTableView")
       self.presentViewController(secondVC, animated: true, completion: nil)

提前致谢!!!

0 个答案:

没有答案