Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.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
Ios 在不显示屏幕的情况下使用segue传递数据_Ios_Swift_Segue - Fatal编程技术网

Ios 在不显示屏幕的情况下使用segue传递数据

Ios 在不显示屏幕的情况下使用segue传递数据,ios,swift,segue,Ios,Swift,Segue,我试图使用segue实现数据传递,但不显示屏幕。我的项目中有两个视图控制器,我将它们命名为FirstViewController和SecondViewController 在FirstViewController上,我使用ShowAdaptive Segue通过performsguewithidentifier传递数据。将调用prepareforsgue方法,并识别我设置为显示SecondViewController的标识符 但是,问题是我不想显示SecondViewController。在前往

我试图使用segue实现数据传递,但不显示屏幕。我的项目中有两个视图控制器,我将它们命名为
FirstViewController
SecondViewController

FirstViewController
上,我使用
Show
Adaptive Segue通过
performsguewithidentifier
传递数据。将调用
prepareforsgue
方法,并识别我设置为显示
SecondViewController
标识符

但是,问题是我不想显示
SecondViewController
。在前往
SecondViewController
之前,我的用户可能还需要做其他事情

我不熟悉iOS编程,我只知道使用segue传递数据。请与我分享,如果有方法传递数据除了segue


编辑:进一步阐述我的问题。我正在使用
TabBarController
,两个
视图控制器都可以在选项卡栏上访问。因此,当我在
SecondViewController
上时,一些数据已经从
FirstViewController
中“分离”出来,我可以返回
FirstViewController
添加更多数据。在
SecondViewController
UIRefreshControl
中,我需要更新的数据

我不确定这是否对您有效,但您可以简单地将数据保存在FirstViewController的内存中,以备用户仍在交互和提供反馈时使用,一旦完成,通过segue将所有数据发送到SecondViewController。

如果以代码方式执行segue,则可以按以下方式执行所需操作

1) 从故事板实例化视图控制器

let storyboard: UIStoryboard = UIStoryboard(name: "SecondViewController", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("set_it_in_IB") as! SecondViewController
2) 设置视图控制器已实例化时需要设置的属性

vc.someProperty = "asd"
3) 塞格


希望有帮助

从用户的角度来看,他们在继续之前不知道数据是否正在更新,因此只需使用
prepareFoSegue
函数传递数据就可以了

否则,您可以尝试将通知设置为
FirstViewController
SecondViewController
上的
viewdiload

NSNotificationCenter.defaultCenter().addObserver(self,选择器:nil,名称:updateSecondVCNotification,对象:nil)

以及在需要使用

NSNotificationCenter.defaultCenter().postNotificationName(updateSecondVCNotification,对象:self)

然后,在第二个视图控制器上,将
addObserver
的选择器设置为您希望它执行的任何函数的名称字符串,如
“reloadNewData”

func重载newdata(){
tableView.reloadData()
}

这有用吗?不要忘记将
updateSecondVCNotification
设置为
FirstViewController
顶部的全局字符串常量。了解有关通知中心的更多信息,请访问


呜!通知(^▽^)/

将数据保存到var中,完成所有操作后,执行该步骤并传递数据。我认为您的方法可能会起作用。不过,为了澄清一下,我正在使用
TabBarController
,两个视图控制器都可以在选项卡栏上访问。因此,当我使用
SecondViewController
时,我会返回
FirstViewController
添加more数据。在
SecondViewController
上,使用
UIRefreshControl
我可以查看更新的数据吗?抱歉。我之前的问题不够清楚。我已经添加了更多信息。对于选项卡,我相信只需在运行时传递数据就可以了。请尝试让SecondViewController=SecondViewController()然后是secondViewController.Whather=?//插入实际数据传输。进入另一个选项卡后,只需刷新显示的数据
viewController.presentViewController(viewControllerToPresent: UIViewController, animated: Bool, completion: (() -> Void)?)