TransitionFromView removes previous view
Asked Answered
A

3

9

I am having problems using TransitionfromView while transitioning between views in my app.

Setup

This is the basic setup of the View Controller. It has two views in it. A MKMapView and a UITableView. When the toggle button is pressed, it is supposed to alternate views between map and table.

This is my *.h file

@interface BrowseBeaconsViewController : UIViewController <UITableViewDelegate, MKMapViewDelegate, UITableViewDataSource, CLLocationManagerDelegate >
{

__weak IBOutlet UIBarButtonItem *refreshBeacons;
__weak IBOutlet UIBarButtonItem *toggleView;
MKMapView* beaconMapView;
__weak IBOutlet UITableView* beaconTableView;
}

So the tableview comes from the storyboard while mapview is created in the program.

Problem

[UIView transitionFromView:beaconTableView toView:beaconMapView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {}];

When I transition from TableView from MapView the value of the tableview is null(0x0000000). I do understand the behaviour of the transitionfromview is to remove the view from the parent view. But when I try add the tableview as a subview after the transition it doesn't work, since the value is null. So my question is how do I add the tableview after the transition if the view is nulled?

PS: I apologize if this is a simple question, but I am new to iOS programming and did try to look in the forums before posting this question.

Artificer answered 8/1, 2013 at 15:58 Comment(0)
H
30

From the docs on that method:

"By default, the view in fromView is replaced in the view hierarchy by the view in toView. If both views are already part of your view hierarchy, you can include the UIViewAnimationOptionShowHideTransitionViews option in the options parameter to simply hide or show them."

So, if you want both views to remain, add the beaconMapView to the view hierarchy, and include the UIViewAnimationOptionShowHideTransitionViews option.

Hudnut answered 8/1, 2013 at 18:23 Comment(2)
This works. But I have another question. How to decide which view is in front? Because I'm using this in a collection view cell.Vermiculite
Thank you. I think this is quite important to know. I was searching around for 10 minsMitrailleuse
I
2

You need to keep a separate reference to beaconTableView or simply declare it as strong instead of weak. Since beaconTableView has been declared as weak, iOS 5+ understands that you don't need it hanging around once all other references to it have been removed, in this case by removing it from its parent view.

Isagoge answered 8/1, 2013 at 16:48 Comment(0)
B
0

Remove weak, otherwise the view gets released as soon as it looks no longer needed.

Bittencourt answered 7/4, 2017 at 8:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.