我是IOS开发的新手.我来自android背景,我想在xcode中实现一个登录.当用户单击登录按钮,如果成功的话,对于first login,它应该转到OTP屏幕,当用户是注册的user...whenever,他/她点击登录按钮,它应该进入主屏幕.因此,基本上我希望login按钮切换到不同的屏幕,(没有导航)
例如,这个功能是登录完成时的。
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
}
}发布于 2017-05-17 06:27:13
您可以连接两个从登录屏幕。
在故事板中,将登录屏幕上的segue连接到OTP屏幕,从登录屏幕连接另一个segue到主屏幕。记住要开始从情节提要中的控制器中拖动,而不是从控制器中的任何视图中拖动。
在右面板中给每个segue一个标识符。我将调用第一个segue (登录-> OTP) "showOTP“和第二个segue (登录->主屏幕) "showHome”。
在综合框架声明中:
func LoginDone() {
if (registeredUser()){
performSegue(withIdentifier: "showOTP", sender: data)
} else {
performSegue(withIdentifier: "showHome", sender: data)
}
}这里我使用data作为sender参数。请用要发送给其他视图控制器的数据来替换它。
然后,重写prepareForSegue
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.
}
}https://stackoverflow.com/questions/44016811
复制相似问题