关闭模态视图控制器不会删除模态视图

时间:2011-04-13 18:10:48

标签: iphone objective-c uitabbarcontroller

我从昨天起就一直在弄清楚这一点,但还没有那么正确。 我已经在我的标签栏控制器上添加了我的加载视图控制器的modalviewcontroller,它工作正常。 在app Delegate:

中添加了代码
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:  (NSDictionary *)launchOptions { 
   [navController.navigationBar setTintColor:[UIColor blackColor]]; 
   [window addSubview:rootController.view]; 
   [window makeKeyAndVisible];
   LoadingViewController *lvc = [[LoadingViewController alloc] initWithNibName:@"LoadingView" bundle:nil]; 
    // Delegate added here
   lvc.loadingDelegate = self;
   [rootController presentModalViewController:lvc animated:YES]; 
   [self URL]; 
   [lvc release]; 
   return TRUE; 
}

现在我进行解析,完成后我在不同的视图名称XMLParsingView.m中调用以下代码,解析结束了。

- (void)handleLoadedApps
 {
 LoadingViewController *loading = [[[LoadingViewController alloc] init] autorelease];
 //delegating to let the load view controller know to dimiss itself by defining  disappear method in protocol
 [loading.loadingDelegate disappear];
 }

并且在加载视图控制器中我有调用dismissModalViewControlAnimated:

的方法
 -(void)disappear{
[activity stopAnimating];
[activity removeFromSuperview];
[self removeFromSuperview];
[self dismissModalViewControllerAnimated:YES];
}

但由于某种原因,它永远不会删除视图,也不会将其加载回我的标签栏控制器。 如果有人遇到过这样的问题,真的需要帮助。

Sagos

2 个答案:

答案 0 :(得分:1)

在你的代码中,你似乎在没有笔尖的情况下创建了一个 new LoadingViewController并立即去掉它。在您的app委托中,您使用nib创建第一个loadingViewController,在rootController上以模态方式呈现它然后释放它。由于你想在你的app委托之外解雇它,你有

3种选择,(最难以最快,最健全)

a)键值 - 从LoadingViewController观察XMLParsingView的属性,以便在任务完成时自行删除。

b)当任务完成时,使用委托通知LoadingViewController。

c)从你的[[UIApplication sharedApplication]委托]中获取你的rootController,这意味着你必须将rootController作为属性或通过方法公开,并使rootController关闭你的模态。

答案 1 :(得分:0)

您需要在dismissModalViewControllerAnimated上调用rootViewController,而不是加载视图控制器。

相关问题