Ios isHidden或view.removeFromSuperView需要很长时间
我尝试从按钮显示UITableView,我尝试了两种不同的方式: 一种是通过一个Ios isHidden或view.removeFromSuperView需要很长时间,ios,swift,Ios,Swift,我尝试从按钮显示UITableView,我尝试了两种不同的方式: 一种是通过一个UIStackViewwith显示,从一开始就被隐藏,而仅通过“isheden”显示,另一种方式是通过另一个UIViewController的视图显示,该视图被称为“didMove(toParentViewController:self)” 无论采用哪种方式,tableview都会立即显示,但要再次隐藏它,需要花费很长时间。 我已尝试将“ishiden=true”放在“DispatchQueue.main.sync”
UIStackView
with显示,从一开始就被隐藏,而仅通过“isheden”显示,另一种方式是通过另一个UIViewController
的视图显示,该视图被称为“didMove(toParentViewController:self)”
无论采用哪种方式,tableview都会立即显示,但要再次隐藏它,需要花费很长时间。
我已尝试将“ishiden=true”放在“DispatchQueue.main.sync”中以使用主线程,但仍然无法按我希望的方式工作
有什么建议吗
以下是我的应用程序的一些代码:
@IBAction func ProfilPicture1Pressed(_ sender: UIButton) {
let popUpTeamDog = storyboard?.instantiateViewController(withIdentifier: "selectTeamDogPopUp") as! SelectTeamDogPopUp
DispatchQueue.global().async(execute: {
DispatchQueue.main.sync{
self.addChildViewController(popUpTeamDog)
popUpTeamDog.view.frame = self.view.frame
self.view.addSubview(popUpTeamDog.view)
popUpTeamDog.didMove(toParentViewController: self)
}
})
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let dog: Dog
if(searching){
dog = searchArray[indexPath.row]
} else {
dog = dogs[indexPath.row]
}
let nameDog = dog.name
//let imgDog = UIImage(named: dog.image)
print(nameDog)
DispatchQueue.global().async(execute: {
DispatchQueue.main.sync{
self.view.removeFromSuperview()
}
})
因此,我可以补充说,当我点击搜索栏,然后选择一只狗,tableView/视图会立即消失,所以当键盘被激活时,效果很好。。。奇怪的事 默认情况下,代码使用主线程。因此,您不必使用这个
DispatchQueue.global()
和DispatchQueue.main
。太慢了
所以换掉这个
DispatchQueue.global().async(execute: {
DispatchQueue.main.sync{
self.addChildViewController(popUpTeamDog)
popUpTeamDog.view.frame = self.view.frame
self.view.addSubview(popUpTeamDog.view)
popUpTeamDog.didMove(toParentViewController: self)
}
})
DispatchQueue.global().async(execute: {
DispatchQueue.main.sync{
self.view.removeFromSuperview()
}
})
与
并对self.view.removeFromSuperview()执行相同的操作。。替换这个
DispatchQueue.global().async(execute: {
DispatchQueue.main.sync{
self.addChildViewController(popUpTeamDog)
popUpTeamDog.view.frame = self.view.frame
self.view.addSubview(popUpTeamDog.view)
popUpTeamDog.didMove(toParentViewController: self)
}
})
DispatchQueue.global().async(execute: {
DispatchQueue.main.sync{
self.view.removeFromSuperview()
}
})
与
是的,首先我尝试不使用所有这些,但速度非常慢,这就是我添加此内容的原因:/Asker在真正的设备上尝试一下,你会发现模拟器可能需要时间,而不是真正的iPhone吗