NSDate 回家时做自己的事情
有一个问题,我不完全明白我哪里出了问题。我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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:.