NSDate 回家时做自己的事情

发布于 2024-10-07 13:29:42 字数 422 浏览 4 评论 0原文

有一个问题,我不完全明白我哪里出了问题。我正在使用 NSDate 用日期和时间填充两个标签。一切运行良好,一旦用户单击应用程序,它就会正确检索日期和时间。

但是,如果我退出应用程序并转到主屏幕然后返回,它不会像我预期的那样重新加载日期/时间。 (我上个月才使用 xcode,所以如果我错过了一些明显基本的东西,我深表歉意。)

我在网上搜索过,但只是变得更加困惑。以前,我在按钮中使用了相同的代码,每次单击它都会按预期返回新的日期和时间 - 认为放入“viewdidload”时它会执行相同的操作。想知道这是否只是模拟器的事情?

我也尝试过发布标签/格式化程序:

[labelDate release];
[dateformatter release;] 

但似乎忽略了这些(尽管听说过 NSDate 自动发布?)。

Have a problem I don't fully understand where I've gone wrong. I'm using NSDate to fill two labels with the date and time. That all runs well, as soon as the user clicks on the app it retrieves the dates and times correctly.

However, if I come out of the app and go to the home screen then go back, it doesn't reload with the date/ time as I would have expected. (I've only been using xcode for the past month so my apologies if I've missed something obviously fundamental.)

I've searched online but just getting further confused. Previously I used the same code in a button and on each click it did return a new date and time as expected - thought it would do the same when put in 'viewdidload'. Wondering if this is only a simulator thing?

Also I've tried releasing the labels/formatter:

[labelDate release];
[dateformatter release;] 

But seems to ignore these (although heard NSDate auto-releases?).

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

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

发布评论

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

评论(1

心的憧憬 2024-10-14 13:29:42

viewDidLoad 仅在第一次初始化视图时调用,而不是每次显示时调用。刷新视图内容的功能应进入 viewWillAppear:

viewDidLoad only gets called the first time your view is initialized, not every time it's displayed. Functionality for refreshing the contents of views should go into viewWillAppear:.

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