Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.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 用户如何在不接触任何按钮/视图的情况下在VCs之间复制Int值?_Ios_Swift - Fatal编程技术网

Ios 用户如何在不接触任何按钮/视图的情况下在VCs之间复制Int值?

Ios 用户如何在不接触任何按钮/视图的情况下在VCs之间复制Int值?,ios,swift,Ios,Swift,是否有任何方法可以复制变量的Int值(顺便说一句,它是子类编号),使用或不使用segue,并且不触摸任何按钮?挑战在于,我的按钮在按下时已经执行了其他功能,此外,返回到上一个视图是通过代码(满足某些条件)而不是用户交互完成的。 谢谢你的想法 下面的方法在编码条件下返回到上一个视图,但我不能用它传递值(子类编号) 在LSViewController中添加一个Int-var(我们称之为var-theInt=0),并执行以下操作: let startView = self.storyboard?.in

是否有任何方法可以复制变量的Int值(顺便说一句,它是子类编号),使用或不使用segue,并且不触摸任何按钮?挑战在于,我的按钮在按下时已经执行了其他功能,此外,返回到上一个视图是通过代码(满足某些条件)而不是用户交互完成的。 谢谢你的想法

下面的方法在编码条件下返回到上一个视图,但我不能用它传递值(子类编号)

在LSViewController中添加一个Int-var(我们称之为
var-theInt=0
),并执行以下操作:

let startView = self.storyboard?.instantiateViewControllerWithIdentifier("startView") as LSViewController
startview.theInt = theInt //the int you want to pass    
self.navigationController?.pushViewController(startView, animated: true)

另外请注意,您的代码不会返回上一个视图,它会在导航控制器堆栈上推送一个新的视图控制器。

谢谢。太好了,它成功了。我在附近写了一些类似的东西,但是你给出了正确的语法,这在我的项目中很有效。
let startView = self.storyboard?.instantiateViewControllerWithIdentifier("startView") as LSViewController
startview.theInt = theInt //the int you want to pass    
self.navigationController?.pushViewController(startView, animated: true)