【问题标题】:dismissModalViewControllerAnimated function not dismissing the viewdismissModalViewControllerAnimated 函数不关闭视图
【发布时间】:2011-01-07 14:27:19
【问题描述】:

我正在尝试使用dismissModalViewController:Animated: 来消除我的观点,但无论我尝试什么,它都不会消除它。您可以在底部的hideSplash 方法中看到我尝试释放视图。请,如果有人可以提供帮助,将不胜感激。我的代码贴在下面:

#import "SplashViewController.h"

@implementation SplashViewController

- (void) didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void) viewDidUnload {

}

- (void) dealloc {
    [super dealloc];
}

-(void) showSplash {
    modalViewController = [[UIViewController alloc] init];
    modalViewController.view = modelView;
    [self presentModalViewController:modalViewController animated:NO];
    [activityIndicator startAnimating ];
    //[self bigcalculation];
    //[self performSelector:@selector(hideSplash) withObject:nil afterDelay:2.0];
}

- (void) viewDidAppear:(BOOL)animated {
    NSLog(@"View Did Appear");
    [self bigcalculation];
}

- (void) bigcalculation {
    NSLog(@"Big Calc Start");
    for (int i = 0; i <= 648230; i++) {
        for (int j = 0; j <= 1200; j++) {

        }
    }
    NSLog(@"Big Calc End");
    [self performSelector:@selector(hideSplash) withObject:nil];
}

- (void) hideSplash {
    NSLog(@"Hide");
    //[self dismissModalViewControllerAnimated:NO];
    //[[self parentViewController] dismissModalViewControllerAnimated:YES];
    [[self modalViewController] dismissModalViewControllerAnimated:YES];
    NSLog(@"End Hide");
}

@end

【问题讨论】:

    标签: ios cocoa-touch uiviewcontroller


    【解决方案1】:

    模态视图控制器不负责解雇。这个负担被放在了调用 modalViewController 的视图控制器上。

    尝试替换:

    [[self modalviewController] dismissModalViewControllerAnimated:YES];
    

    [self dismissModalViewControllerAnimated:YES];
    

    【讨论】:

    • 看看我已经尝试过的代码,这就是为什么被注释掉了。
    • 您可以在模态视图控制器上调用dismissModalViewControllerAnimated: 并将其转发给父级。这也可用于关闭连续呈现的模态视图控制器的“堆栈”(如文档中所述)。
    • 其实马克,我们要解散的控制器应该是接收器。它可能被呈现视图控制器调用,但方法的接收者应该是解雇者。
    • 这在 iOS 5 中是正确的。在框架的早期版本中,父视图控制器负责解除。父视图控制器的概念现在已经改变。
    【解决方案2】:

    我找到了解决方案,以防其他人遇到此问题

    [self performSelector:@selector(hideSplash) withObject:nil];
    

    应该是

    [self performSelector:@selector(hideSplash) withObject:nil afterDelay:0.0];
    

    【讨论】:

    • 你可以用[self performSelectorOnMainThread:@selector(hideSplash) withObject:NULL waitUntilDone:NO];替换它,因为你需要一个单独的线程来更新UI。
    【解决方案3】:

    尝试使用这个:

    [self.parentViewController dismissModalViewControllerAnimated:NO];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多