簡體   English   中英

查看未從堆棧中卸載

[英]View not unloading from stack

我是新手,我遇到以下問題,希望有人可以幫助我。 當我的應用程序加載時,它具有幾個按鈕,可加載不同的UIWebViews,每個按鈕都有一個后退按鈕。 第一個視圖可以很好地加載,並且當您按下“后退”按鈕時,您可以回到主視圖,但是,當您加載第二個視圖時,第一個URL會再次加載,而當您按下“后退”按鈕時,它將加載第二個視圖。

似乎第一個視圖沒有從該視圖中卸載。 如果有誰能幫上忙,那就大感激了。 這是我的代碼。

加載每個視圖

-(IBAction)displayLocationView:(id)sender {
locationViewController = [[LocationViewController alloc]initWithNibName:@"LocationViewController" bundle:nil];


[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];

[self.view addSubview:locationViewController.view];
[UIView commitAnimations];
}

加載URL

-(void)viewDidLoad {
[super viewDidLoad];

NSURL *url = [NSURL URLWithString:@"http://www.kingsgroversl.com.au"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

[webView loadRequest:request];
}

卸載每個視圖並返回主屏幕

-(IBAction)backButton:(id)sender {

[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view.superview cache:YES];

[self.view removeFromSuperview];
[UIView commitAnimations];
}

提前致謝。

問題在這里

-(IBAction)backButton:(id)sender {

[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view.superview cache:YES];

[self.view removeFromSuperview];// change this to

[locationViewController.view removeFromSuperview]; [UIView commitAnimations]; }

您需要更改上述行。 目前,您正在執行的操作是刪除sel.view...。這是不正確的。 您需要刪除子視圖。 像這樣

[locationViewController.view removeFromSuperview];

希望這個能對您有所幫助

當您使用removefromsuperview時,它意味着您要從superview中移除。但不是從內存中移除。因此,最好使用[self.navigationcontroller pushviewcontroller:animatedviewcontroller animation:YES];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM