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 如何在屏幕之间动态切换_Ios_Swift - Fatal编程技术网

Ios 如何在屏幕之间动态切换

Ios 如何在屏幕之间动态切换,ios,swift,Ios,Swift,我是IOS开发新手……我来自androidbackground 我想在xcode中实现登录。。。 当用户单击登录按钮时,如果成功,对于首次登录,它应该进入OTP屏幕,并且在用户成为注册用户后…每当他/她单击登录按钮时,它应该进入主屏幕。。。 因此,基本上我希望登录按钮切换到不同的屏幕(无导航) 例如,当登录完成时,此函数为 func LoginDone() { if (registeredUser()){ //switch to OTP screen and also send

我是IOS开发新手……我来自
android
background 我想在xcode中实现登录。。。 当用户单击登录按钮时,如果成功,对于
首次登录
,它应该进入OTP屏幕,并且在用户成为注册用户后…每当他/她单击登录按钮时,它应该进入主屏幕。。。 因此,基本上我希望
登录
按钮切换到不同的屏幕(无导航)

例如,当登录完成时,此函数为

func LoginDone()
{
    if (registeredUser()){
     //switch to OTP screen and also send The username to that .swift file
    }

    else{
     //switch to homescreen and send some data to that .swift file
    }     
}

您可以从登录屏幕连接两个分段

在故事板中,将一个序列从登录屏幕连接到OTP屏幕,将另一个序列从登录屏幕连接到主屏幕。记住从情节提要中的控制器开始拖动,而不是从控制器中的任何视图开始拖动

在右侧面板中为每个序列指定一个标识符。我将调用第一个segue(登录->OTP)“showOTP”,第二个segue(登录->主屏幕)“showHome”

在if语句中:

func LoginDone() {

    if (registeredUser()){
         performSegue(withIdentifier: "showOTP", sender: data)
    } else {
         performSegue(withIdentifier: "showHome", sender: data)
    }

}
这里我使用了
data
作为
sender
参数。请将其替换为要发送到其他视图控制器的数据

然后,覆盖
prepareforsgue

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "showOTP" {
        let vc = segue.destination as! OTPController // Here replace OTPController with the class name of the OTP screen
        vc.username = sender as! String // username is a property in OTPController used to accept the value passed to it. If you don't have this, declare it.
    } else if segue.identifier == "showHome" {
        let vc = segue.destination as! HomeController // Here replace HomeController with the class name of the home screen
        vc.data = sender as! SomeType // data is a property in HomeController used to accept the value passed to it. If you don't have this, declare it.
        // replace SomeType with the type of data you are passing.
    }
}

你在使用故事板吗?是的,我现在正在使用故事板…你可以使用segue进入不同的屏幕并给每个segue一个标识符。谢谢你的帮助…解释得很好