【问题标题】:How to call viewWillAppear with storyboard iOS7如何使用情节提要 iOS7 调用 viewWillAppear
【发布时间】:2014-12-16 10:20:55
【问题描述】:

我正在使用故事板。 正如我所记得的(我很久以前使用 ios 4 =))每次,当 View 出现时,调用

-(void)viewWillAppear:(BOOL)Animated {}

方法。 现在这个方法不会调用,如果我按下 Home 按钮并再次运行应用程序。

如何解决?

我需要更新一个 UIView,如果它在按下主页后出现。

【问题讨论】:

  • 实际上viewWillAppear 的行为仍然相同。它在视图出现时触发...一定是其他地方出错了。
  • viewWillAppearUIViewController 的一部分,而不是UIView。看我的回答。

标签: objective-c ios7 storyboard


【解决方案1】:

函数viewWillAppear 不是UIView 的一部分。它是UIViewController 的一部分。

它在视图控制器的视图被加载之后并且就在它开始转换到屏幕上之前被调用。

如果您创建UIView 的子类并将此函数放入其中,那么它将永远不会被调用,因为它不应该被调用。

编辑

当应用从后台返回时,viewWillAppear 不会被调用是正确的。

如果您想在发生这种情况时更新应用的一部分,那么您可以在 AppDelegate 中执行一些操作。

我建议不要尝试将属性等存储在 AppDelegate 中。你应该做这样的事情......

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

    // just pass the message on. In your view you will need to add an observer for this notification
    [[NSNotificationCenter defaultCenter] postNotificationName:@"UpdateViewNotification" object:nil];
}

【讨论】:

  • 好的,我如何为指定视图调用我的更新函数,以及如何捕捉它是否从后台出现? AppDelegate 方法?
  • @Arthur 啊,我明白了。我不太了解主页按钮的内容。我会更新的。
【解决方案2】:

试试这个,打电话给超级,

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    相关资源
    最近更新 更多