重新加载或刷新 UIView?

发布于 2025-01-06 06:17:49 字数 378 浏览 1 评论 0原文

我的应用程序允许用户通过应用程序内购买来解锁一系列级别。为了表明某个级别已锁定,我将图标 alpha 更改为 0.7,只是为了将其与他们拥有/可以访问的级别区分开来。

我的代码通过检查 NSUserDefaults 上 viewDidLoad 上的 BOOL 键来工作:

if(![[NSUserDefaults standardUserDefaults] boolForKey:@"com.productbundle.unlock"]){
    //set these levels to alpha = 0.7
}

因此,在他们成功购买后,如果我可以刷新/重新加载 UIView,那将非常容易。有办法做到这一点吗?或者有其他方法可以达到这种效果吗?谢谢

My app allows a user to unlock a bunch of levels with an in app purchase. To indicate that a level is locked, I change the icon alpha to 0.7, just to differentiate it from levels they own/can access.

My code works by checking the NSUserDefaults for a BOOL key on viewDidLoad:

if(![[NSUserDefaults standardUserDefaults] boolForKey:@"com.productbundle.unlock"]){
    //set these levels to alpha = 0.7
}

So after they successfully purchase, it would be really easy if I could just refresh/reload the UIView. Is there a way to do this? Or is there alternate way I can achieve this affect? Thanks

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

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

发布评论

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

评论(3

帝王念 2025-01-13 06:17:49

我认为你不应该调用 [self viewDidLoad]。据我了解,这些是您在子类中实现的更多方法,用于响应各种事件,通常您不应该自己调用它们。更多地查看视图的文档,如果您想在视图再次可见时刷新内容,请考虑实施

-(void)viewDidAppear:(BOOL)animated

I don't think you should be calling [self viewDidLoad]. As I understand it those are more methods you implement in your subclass to respond to various events and in general you shouldn't call them yourself. Looking more at the documentation for views, if you want to refresh stuff when a view becomes visible again look into implementing

-(void)viewDidAppear:(BOOL)animated
一抹苦笑 2025-01-13 06:17:49

我会将其放入 -(void)viewWillAppear:(BOOL)animated

viewWillAppear =“通知视图控制器其视图即将变得可见。”

我会检查您的用户默认值,并在其中粘贴 if 语句:

- (void)viewWillAppear:(BOOL)animated
{
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        if ([defaults boolForKey:@"com.productbundle.unlock"] == YES) {
            //set alpha to 1
        };


    [super viewWillAppear:animated];
}

I would put it in -(void)viewWillAppear:(BOOL)animated

viewWillAppear = "Notifies the view controller that its view is about to be become visible."

I'd check for your user defaults, and stick an if statement in there:

- (void)viewWillAppear:(BOOL)animated
{
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        if ([defaults boolForKey:@"com.productbundle.unlock"] == YES) {
            //set alpha to 1
        };


    [super viewWillAppear:animated];
}
开始看清了 2025-01-13 06:17:49

使用 setNeedsDisplay 刷新 UIView。

[yourUIView setNeedsDisplay];

use the setNeedsDisplay to refresh a UIView.

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