简体   繁体   English

动画之前在UICollectionView中使用Core Data加载数据

[英]Load data with Core Data in UICollectionView before animation

I am pretty new to iOS development, but I could not find an answer to this question (maybe I could not find the right keywords to search..?). 我是iOS开发的新手,但是我找不到这个问题的答案(也许我找不到合适的关键词来搜索..?)。

Anyway, I have this "problem": 无论如何,我有这个“问题”:

I have 2 storyboards, A and B, both with some views inside. 我有两个情节提要A和B,里面都有一些视图。 I go from view A-2 to view B-1 via @IBAction - a simple button click - with the following code: 我通过以下代码从@AAction从视图A-2转到视图B-1:一个简单的按钮单击-

 @IBAction func onExercisesButtonTapped(_ sender: AnyObject) {
    let storyboard = UIStoryboard(name: "Exercises", bundle: nil)
    let controller = storyboard.instantiateViewController(withIdentifier: "ExercisesVC") as UIViewController

    controller.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
    present(controller, animated: true, completion: nil)    
}

On the other hand, in the B-1 view I have a UICollectionView that is populated with data coming from a CoreData model. 另一方面,在B-1视图中,我有一个UICollectionView,其中填充了来自CoreData模型的数据。 The cells within the UICollectionView appear only after the animation is completed. UICollectionView中的单元格仅在动画完成后出现。 If I set animated: false in the perform function and thus no animation is performed from A-2 view to B-1 view the cells are immediately visible. 如果我在Perform函数中设置了animated:false,则不会从A-2视图到B-1视图执行任何动画,这些单元格立即可见。

The cells are the only element that appear after the completion of the animation. 单元格是动画完成后出现的唯一元素。 What is the cause of this behaviour? 这种行为的原因是什么? Can I avoid it with some sort of preloading/prefetching or other methods? 我可以通过某种预加载/预取或其他方法来避免这种情况吗?

Is there a way to display the cells before the animation starts, just like the UICollectionView background and all the other elements within the view? 有没有一种方法可以在动画开始之前显示单元格,就像UICollectionView背景和视图中的所有其他元素一样?

Thank you in advance :) 先感谢您 :)

viewWillAppear:更新视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM