在下一个视图中编辑标签很长

时间:2017-06-14 15:23:23

标签: ios swift

我的简单iOS应用程序有点问题: 只有2个视图,第一个将数据发送到第二个(异步,然后在下载数据之前显示第二个数据,但是当我在控制台中打印这些数据时,我可以看到它们被非常快速地下载。)

问题是我必须等待几秒钟(10到20秒之间)才能看到label更改。 只有label才会出现此问题,例如我在imageView之后填充label,并立即应用图片上的更改。

以下是第一个视图的代码:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if (segue.identifier == "profilevc")
        {
            let dvc = segue.destination as! ProfileController;
            dvc.data = self.loginField.text;
            _ = ftRemote(login: dvc.data, view: dvc);
        }
    }

以下是ftRemote()中调用的函数,其中填充了label

    private func populateView(user: UserProfile)
    {
        self.pfView.loginLabel.text = user.login;
        self.pfView.fullnameLabel.text = user.firstname! + " " + user.lastname!;
        self.pfView.phoneLabel.text = user.phone;
        self.pfView.walletLabel.text = "Wallet: " + String(Int(user.wallet!))
        self.pfView.correctionLabel.text = "Correction: " + String(Int(user.correctionPoints!))
        self.pfView.levelLabel.text = String(Float(user.level!))
        self.pfView.profilePicture.downloadedFrom(link: user.imageUrl!)
    }

有人可以解释这种延迟吗?

由于

1 个答案:

答案 0 :(得分:0)

确保在主线程中执行与UI相关的内容。像这样打电话给你populateView

DispatchQueue.main.async {
    // actions with you UI, e.g. populateView(...) call
}