Swift-从外部服务器进行验证后,如何以编程方式更改视图

时间:2018-10-15 02:42:32

标签: ios swift validation login server

我有一个登录视图页面,一旦登录经过验证,该页面应过渡到选项卡视图控制器。但是,在session.dataTask

中实例化视图时出现错误。
[24249:381955] [Animation] +[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior.

哪个会导致

terminating with uncaught exception of type NSException

从服务器进行验证后,如何验证用户并将其带到主页?

1 个答案:

答案 0 :(得分:2)

这是因为您不应该在后台线程上执行该操作。

将实例化代码移入主线程

DispatchQueue.main.async { 
// view instantition here.
}