viewWillAppear
is called both when going to the view and when coming back to the view from other views.
I want to select(highlight) and fade-out a cell only when coming back from other views.
Is there a delegate method to do this?
I'm using UINavigationViewController.
If you're on iOS 5, you can use these new properties:
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);
In your code:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (!(self.isMovingToParentViewController || self.isBeingPresented))
{
// animate
}
}
EDIT:
If you're using a UITableViewController
, setting the property -clearsSelectionOnViewWillAppear
to YES
will do this for you. You only have to do it manually if you're using a regular UIViewController
with a UITableView
subview.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With