TransitionFromView deletes the previous view

I am having problems using TransitionfromView when switching between views in my application.

Customization

This is the basic setting of the view controller. It has two types. MKMapView and UITableView. When the switch button is pressed, it should alternate views between the map and the 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 table view 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 moving from a TableView to a MapView, the value of tableview is null (0x0000000). I understand that transition behavior is to remove a view from its parent view. But when I try to add a tableview as a preview after the transition, it does not work as the value is null. So my question is how to add a table view after the transition, if the view is nullified?

PS: I apologize if this is a simple question, but I'm new to iOS programming and tried to look at the forums before posting this question.

+8
ios uitableview uiviewanimationtransition
source share
3 answers

In the docs on this method:

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

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

+29
source share

You need to leave a separate link to the beaconTableView or just declare it strong, not weak. Since beaconTableView is declared weak, iOS 5+ understands that you don’t need to wag it as soon as all other links to it have been deleted, in this case, removing it from the parent view.

+2
source share

Delete weak, otherwise the presentation will be released as soon as it is no longer needed.

0
source share

All Articles