基于iOS的APP“好妈妈”开发日志十四——关于UIAlertController自动消失并跳转至下一页面
基于leancloud的注册系统
//注册按钮点击
@objc func loginConfrim(){
//收起键盘
self.view.endEditing(true)
let user = LCUser()
user.username = LCString(txtUser.text!)
user.password = LCString(txtPwd.text!)
print("**************************************")
user.signUp { (x) in//注册
if let error=x.error
{
self.present(self.alert, animated: true, completion: nil)//登录失败弹出提示框
print(error.code)
}
else{
print("signUp sucess")
self.present(self.alertSucceed, animated: true, completion: nil)//登录成功弹出提示框
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {//延迟函数
LCUser.logIn(username: self.txtUser.text!, password: self.txtPwd.text!) { result in//注册成功后就登录
switch result {
case .success(let user):
print("Login succeed")
//登录成功则弹出下一页面Tabbar
let first = self.storyboard//A视图
let thirdView:UIViewController = (first?.instantiateViewController(withIdentifier: "TarBar"))!
self.alertSucceed.present(thirdView, animated: true, completion: nil)//由B视图弹出C
thirdView.presentedViewController?.dismiss(animated: false, completion: nil)
break
case .failure(let error):
self.present(self.alert, animated: true, completion: nil)//登录失败弹出提示框
print(error)
}
}
}
}
}
}
简单地说就是A视图先弹出Alert(B视图),然后在延时函数里由Alert弹出C页面,弹出后再用C的presented.dismiss使A和B消失。
多层view试图嵌套弹出即消失参考文章《iOS 聊聊present和dismiss》https://www.jianshu.com/p/455d5f0b3656
luhh!?