简体   繁体   English

TransitionFromView删除以前的视图

[英]TransitionFromView removes previous view

I am having problems using TransitionfromView while transitioning between views in my app. 我在我的应用程序中的视图之间转换时使用TransitionfromView时遇到问题。

Setup 建立

This is the basic setup of the View Controller. 这是View Controller的基本设置。 It has two views in it. 它有两个视图。 A MKMapView and a UITableView. 一个MKMapView和一个UITableView。 When the toggle button is pressed, it is supposed to alternate views between map and table. 按下切换按钮时,应该在地图和表格之间交替显示视图。

This is my *.h file 这是我的* .h文件

@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. 因此,tableview来自故事板,而mapview是在程序中创建的。

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). 当我从MapView从MapView转换时,tableview的值为null(0x0000000)。 I do understand the behaviour of the transitionfromview is to remove the view from the parent view. 我确实理解transitionfromview的行为是从父视图中删除视图。 But when I try add the tableview as a subview after the transition it doesn't work, since the value is null. 但是当我尝试在转换后将tableview添加为子视图时它不起作用,因为该值为null。 So my question is how do I add the tableview after the transition if the view is nulled? 所以我的问题是如果视图为空,我如何在转换后添加tableview?

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. PS:我很抱歉,如果这是一个简单的问题,但我是iOS编程的新手,并且在发布此问题之前尝试查看论坛。

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." “默认情况下,fromView中的视图在视图层次结构中由toView中的视图替换。如果两个视图都已经是视图层次结构的一部分,则可以在options参数中包含UIViewAnimationOptionShowHideTransitionViews选项,以便隐藏或显示它们。”

So, if you want both views to remain, add the beaconMapView to the view hierarchy, and include the UIViewAnimationOptionShowHideTransitionViews option. 因此,如果要保留两个视图,请将beaconMapView添加到视图层次结构中,并包含UIViewAnimationOptionShowHideTransitionViews选项。

You need to keep a separate reference to beaconTableView or simply declare it as strong instead of weak. 您需要对beaconTableView保持单独的引用,或者只是将其声明为强而不是弱。 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. 由于beaconTableView已被声明为弱,因此iOS 5+了解一旦删除了对其的所有其他引用,就不需要它,在这种情况下,将其从父视图中删除。

删除弱,否则视图会在看起来不再需要时立即释放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM