gpt4 book ai didi

iPhone:viewWillAppear 仅在从其他 View 返回时出现

转载 作者:可可西里 更新时间:2023-11-01 05:01:34 30 4
gpt4 key购买 nike

viewWillAppear 在进入 View 和从其他 View 返回 View 时都会被调用。

我只想在从其他 View 返回时选择(突出显示)并淡出一个单元格。

是否有委托(delegate)方法来执行此操作?

我正在使用 UINavigationViewController。

最佳答案

如果您使用的是 iOS 5,则可以使用这些新属性:

These four methods can be used in a view controller's appearance callbacks to determine if it is being presented, dismissed, or added or removed as a child view controller. For example, a view controller can check if it is disappearing because it was dismissed or popped by asking itself in its viewWillDisappear: method by checking the expression ([self isDismissing] || [self isMovingFromParentViewController]).

- (BOOL)isBeingPresented __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
- (BOOL)isBeingDismissed __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);

- (BOOL)isMovingToParentViewController __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
- (BOOL)isMovingFromParentViewController __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);

在您的代码中:

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

if (!(self.isMovingToParentViewController || self.isBeingPresented))
{
// animate
}
}

编辑:

如果您使用的是 UITableViewController,将属性 -clearsSelectionOnViewWillAppear 设置为 YES 即可为您执行此操作。如果您使用带有 UITableView subview 的常规 UIViewController,则只需手动执行此操作。

关于iPhone:viewWillAppear 仅在从其他 View 返回时出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10949440/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com