我需要保留子視圖控制器解除後將其移回需要時沒有額外的子視圖控制器處理。我曾嘗試使用下面的鏈接實現它:如何在移回父級後保留子視圖控制器(容器實現)?
How does View Controller Containment work in iOS 5?
這些鏈接(以及類似的其他人)都將成爲子視圖控制器或貶,但不是「保留它」的目的。請在下面找到我的代碼:
/* Adding a child view controller */
self.detailsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailsViewController"];
self.detailsViewController.name = @"DetailsText";
// data to do "processing in viewDidLoad of child"
self.detailsViewController.someOtherDataForProcessing = someOtherDataForProcessing;
self.detailsViewController.delegate = self;
[self addChildViewController:self.detailsViewController];
self.detailsViewController.view.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 200);
[self.view addSubview:self.detailsViewController.view];
/* Bringing the child up on swipe gesture */
[UIView animateWithDuration:0.5 animations:^{
self.detailsViewController.view.frame = CGRectMake(0, 100, self.view.frame.size.width, 200);
} completion:^(BOOL finished) {
[self.detailsViewController didMoveToParentViewController:self];
}];
/* Moving child down when back pressed on child */
[UIView animateWithDuration:0.5 animations:^{
[self.detailsViewController willMoveToParentViewController:nil];
self.detailsViewController.view.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 200);
} completion:^(BOOL finished) {
[self.detailsViewController.view removeFromSuperview];
[self.detailsViewController removeFromParentViewController];
}];
,如果我需要「刷卡上再次父」把孩子控制,我不得不再次經歷的整個過程。我需要做的只是「讓孩子在滑動手勢上」過程,而不是再次實例化,因爲實例化將在子控制器中處理數據(耗時)。
我是iOS應用程序編程的noob,所以如果這是一個明顯的問題,請耐心等待。
如何聲明'self.detailsViewController'?它應該是'強'。 – Cyrille
@property(強,非原子)DetailsViewController * detailsViewController; 我認爲這個問題是在這幾行: [self.detailsViewController willMoveToParentViewController:nil]; [self.detailsViewController.view removeFromSuperview]; [self.detailsViewController removeFromParentViewController]; 但我不能刪除它們可以嗎? –