"Unable to Load"消息在今天的小部件



我介于我的小部件开发之间。由于我们已经将我们的应用程序与小部件集成在一起。但是现在几天,我在iOS中遇到了今天的小部件的问题。我已经为两种情况编写了代码。第一次当小部件第一次在应用程序启动时首次加载时,它会调用 Web 服务并通过互联网获取数据,然后将它们存储到用户默认值中以供以后使用。

现在,下次用户下拉通知菜单时,我们首先向用户显示我们存储的旧内容,然后我们从 Web 服务中获取它并存储在用户默认值中,然后再次重新加载表。

对于上述操作,在某些情况下,我遇到了表格的内容大小问题,闪烁问题和"无法加载"消息。

现在看看下面的代码,我在下面的方法中进行网络调用,在 Web 服务的响应之后,我只处理完成处理程序。

- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
    // Perform any setup necessary in order to update the view.
    // If an error is encountered, use NCUpdateResultFailed
    // If there's no update required, use NCUpdateResultNoData
    // If there's an update, use NCUpdateResultNewData
    [self getBookedAppointmentsNew:completionHandler];
}

所以,请与我分享你的经验和想法。

一般来说,每当小部件崩溃时,我都会看到"无法加载"消息。小部件尝试加载自身,如果它反复崩溃,那么它只会显示"无法加载"消息。调试您的小部件并确保没有任何内容导致其崩溃

最后,我找到了解决问题的方法。请查看下面的代码。

在 viewDidLoad() 方法中,我刚刚将视图的首选内容大小设置为启动时显示底部视图所需的基本高度,然后我进行了 Web 服务调用来获取数据。获取数据后,我再次设置了 TodayWidget 视图的首选内容大小。

-(void)viewDidLoad
{
    [super viewDidLoad];
    self.bottomView.frame = CGRectMake(self.bottomView.frame.origin.x, 0.0, self.bottomView.frame.size.width, self.bottomView.frame.size.height);
    self.preferredContentSize = CGSizeMake(self.view.frame.size.width, self.bottomView.frame.size.height);
    [self getBookedAppointmentsNew];
}
-(void)getBookedAppointmentsNew
{
    //-- After web-service response (positive/negative), I have set again the preferred content size.
    self.bottomView.frame = CGRectMake(self.bottomView.frame.origin.x, self.scrollView.frame.size.height, self.bottomView.frame.size.width, self.bottomView.frame.size.height);
    self.preferredContentSize = CGSizeMake(self.view.frame.size.width, (self.bottomView.frame.origin.y + self.bottomView.frame.size.height));
}

我已按照上述步骤解决了有关"无法加载"和"屏幕闪烁"的问题。

您的小部件界面的布局约束可能不是唯一的。没有任何布局约束的视图可能会剪裁其内容或重叠其他视图。

最新更新