在互联网上同步后刷新/重新加载视图

发布于 2024-09-12 10:47:07 字数 563 浏览 2 评论 0原文

我正在编写 iPhone 应用程序,它定期与同步 Web 服务同步。一切正常,但不幸的是,同步后,如果用户之前访问过视图,则看不到视图中的任何更改。

我需要强制重新加载/刷新一些视图。我该如何使用 viewWillAppear 方法来做到这一点?

我在我的一个视图控制器中尝试过类似的操作:

-(void) viewWillAppear:(BOOL)animated   
{
        NSArray* sbw = [self.view subviews];

        UIView* view;
        for (view in sbw) 
        {
            [view setNeedsDisplay];
        }

        [self.view setNeedsDisplay];
        [super viewWillAppear];

    }

但是子视图并不刷新。有没有强制重新加载/刷新视图的方法?

我知道当我移动到这个视图时 viewWillAppear 会被执行,但它并不刷新 - 那么我该怎么做呢?

I'm writing iPhone application which periodically is syncing with the synchronization web service. Everything works ok, but unfortunately after synchronization user do not see any changes in the view if he visited it before.

I need to force to reload/refresh some of views. How could I do that with for example viewWillAppear method?

I've tried something like this in one of my view controllers:

-(void) viewWillAppear:(BOOL)animated   
{
        NSArray* sbw = [self.view subviews];

        UIView* view;
        for (view in sbw) 
        {
            [view setNeedsDisplay];
        }

        [self.view setNeedsDisplay];
        [super viewWillAppear];

    }

But the subviews are not refreshing. Is there any method for forcing to reload/refresh view?

I know that viewWillAppear is executed when I move to this view but it's not refreshing - so how can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别在捏我脸啦 2024-09-19 10:47:07

在表格视图中,您可以使用:[tableView reloadData];来重新加载表格内容。如果您只想更新视图内容,只需更改它即可。假设您有一个视图类和一个控制器类 MyUIViewMyUIViewController 并且 MyUIView 确实包含一个 UILabel * myLabel 您可以通过以下方式更改控制器内的标签文本:

[((MyUIView *)self.view).myLabel setText:@"This is a new text."];

因此无需强制更新。

in tableviews you could use : [tableView reloadData]; to reload a tables content. If you just want to update the views content you could just change it. Lets say if you have a view class and a controller class MyUIView and MyUIViewController and MyUIView does contain an UILabel * myLabel you could change the label text inside the controller by:

[((MyUIView *)self.view).myLabel setText:@"This is a new text."];

so no need for forcing update.

久光 2024-09-19 10:47:07

您可以编写“viewWillAppear”方法,因为您可以编写要重新加载的代码,该代码可能会从数据库中获取数据。当视图开始加载时,将执行该方法。

You can write the method "viewWillAppear" in that you can write your code to be reloaded which may take the data from your data base.This method will be executed when ever the view starts to load.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文