当应用程序变得活跃时,刷新Parse.com数据。

时间:2022-08-13 15:50:31

[Edited with solution below]

(与下面的解决方案编辑)

I want to call a Parse.com query whenever the app becomes active, so that if it's brought up from the foreground, a new set a data will be called.

每当应用程序变得活跃时,我都要调用Parse.com查询,这样如果它从前台打开,就会调用一个新集合a data。

I realize there is a method for this in the AppDelegate

我知道在AppDelegate中有一个方法

- (void)applicationDidBecomeActive:(UIApplication *)application {

}

But I want to know how I can put the query information obtained in my AppDelegate and put it in my ViewController where I can display the information.

但是我想知道如何将在AppDelegate中获得的查询信息放到ViewController中我可以显示信息。

Any ideas on what I might do? Or if there is another way to make the query when the app becomes active? Thanks.

你知道我该怎么做吗?或者当应用程序变得活跃时,是否有其他方法进行查询?谢谢。

So here is what I came up with. I had my method (called getData) in the ViewController, and in the viewDidLoad method, I inserted this code

这就是我想到的。我在ViewController中有我的方法(称为getData),在viewDidLoad方法中,我插入了这个代码。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getData)

 name:UIApplicationDidBecomeActiveNotification object:nil];

And now it works just as I had hoped. Thanks!

现在它就像我希望的那样运作。谢谢!

1 个解决方案

#1


1  

This is a really broad question, but what you can do is you can post a notification and make your view controller listen to it.

这是一个很宽泛的问题,但是你能做的是发布一个通知并让你的视图控制器听它。

Then after your app re enter from background, you can post the notification and in the observer method that you implemented in the view controller, you can pull the data from Parse.

然后,在应用程序从后台重新输入后,您可以发布通知,在视图控制器中实现的observer方法中,您可以从Parse中提取数据。

See this question to understand the sequence of the method calls.

要理解方法调用的顺序,请参见这个问题。

#1


1  

This is a really broad question, but what you can do is you can post a notification and make your view controller listen to it.

这是一个很宽泛的问题,但是你能做的是发布一个通知并让你的视图控制器听它。

Then after your app re enter from background, you can post the notification and in the observer method that you implemented in the view controller, you can pull the data from Parse.

然后,在应用程序从后台重新输入后,您可以发布通知,在视图控制器中实现的observer方法中,您可以从Parse中提取数据。

See this question to understand the sequence of the method calls.

要理解方法调用的顺序,请参见这个问题。