iPhone SDK重新加载UIView的内容

发布于 2024-08-25 19:52:24 字数 370 浏览 12 评论 0原文

我有两个视图,一个视图占据整个屏幕,第二个视图仅覆盖一小部分。我想要的是第二个视图位于第一个视图上(我已经完成了),但问题是,当我设置值(在本例中为 UILabel)时,屏幕上的标签不会显示该新值。我知道该方法确实被调用,但由于某种原因它不会改变标签的值。

编辑:这是代码:

-(void)loadHighScores
{   
[no1 setText:@"test"];
 NSLog(@"it works");
}

这就是我如何称呼它:

    highscore = [[HighScore alloc] init];
    [highscore loadHighScores];

I have two views, one view takes the whole screen, the second view covers only a little portion. What I want is for that second view to be on the first view (which I already have done), but the problem is, when I set values (in this case UILabel's) the label on the screen doesn't display that new value. I know for a fact the method gets called, but for some reason it won't change the label's value.

Edit: Here's the code:

-(void)loadHighScores
{   
[no1 setText:@"test"];
 NSLog(@"it works");
}

And here's how I call it:

    highscore = [[HighScore alloc] init];
    [highscore loadHighScores];

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

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

发布评论

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

评论(1

桃酥萝莉 2024-09-01 19:52:24

您是否尝试过:

[myView setNeedsDisplay];

引用Apple文档:

默认情况下,几何图形会更改为视图
自动重新显示视图
无需调用
绘制矩形:方法。因此,您需要
仅请求视图重绘
当数据或状态用于
绘制视图发生变化。在这种情况下,
发送视图 setNeedsDisplay
信息。任何标记为的 UIView 对象
需要显示的会自动
应用程序时重新显示
返回到运行循环。

Have you tried:

[myView setNeedsDisplay];

Quote from Apple docs:

By default, geometry changes to a view
automatically redisplays the view
without needing to invoke the
drawRect: method. Therefore, you need
to request that a view redraw only
when the data or state used for
drawing a view changes. In this case,
send the view the setNeedsDisplay
message. Any UIView objects marked as
needing display are automatically
redisplayed when the application
returns to the run loop.

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