gpt4 book ai didi

widget - iOS 8 Today Widget 中 widgetPerformUpdateWithCompletionHandler 的用途是什么?

转载 作者:行者123 更新时间:2023-12-03 03:22:03 25 4
gpt4 key购买 nike

一直在寻找答案,但一切似乎都很模糊或不清楚。

无论如何,只是想知道该函数的目的是什么:

widgetPerformUpdateWithCompletionHandler

在今日小部件中执行此操作。

根据Apple :

This method is called to give a widget an opportunity to update its contents and redraw its view prior to an operation such as a snapshot. When the widget is finished updating its contents (and redrawing, if necessary), the widget should call the completion handler block, passing the appropriate NCUpdateResult value.

快照什么时候发生?每当我调试扩展时,widgetPerformUpdateWithCompletionHandler 总是在 loadView 之后被调用。那么当我已经在loadView中加载信息时,在这个方法中显式地重新加载信息的目的是什么呢?


根据该网站:http://www.karlmonaghan.com/tag/today-widget/

In the TodayViewController, there are two places that need to load data from the network – when the widget is created and when widgetPerformUpdateWithCompletionHandler is called. For the former, I load posts in viewDidLoad, so that they should be ready by the time the widget displays. When iOS thinks the widget will be displayed to the user after it has been first displayed, widgetPerformUpdateWithCompletionHandler is called giving the widget a chance to update the posts displayed.

与上面相同的问题。

最佳答案

不会在每次查看通知中心时创建小部件,因此不会在每次显示时调用 loadView。当通知中心认为需要更新小组件信息时,它会调用 widgetPerformUpdateWithCompletionHandler。从我自己的调试看来,当小部件最初创建时,widgetPerformUpdateWithCompletionHandler几乎立即被调用,因此您可以在那里完成所有加载,但Apple建议您尽早开始加载过程。尽可能的生命周期。

如果您的小部件显示的信息从不更改,那么您无需在 widgetPerformUpdateWithCompletionHandler 中执行任何操作。

关于widget - iOS 8 Today Widget 中 widgetPerformUpdateWithCompletionHandler 的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25168950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com