ModalViewController不出现在按钮上按

问题描述:

我有这个ViewController与它的UIButton。这个按钮触发一个方法,这应该在他的位置提供一个modalVC。但由于某种原因,它不再工作了。我以前一直使用相同的代码,没有任何问题,但它却让我感到困惑。ModalViewController不出现在按钮上按

-(void)showModalVC //the method that's being fired by the button. 
{ 
    NSLog(@"modalVC to create a table"); //this log is being printed so the button fires as proper. 

    self.myModalVC = [[MyModalViewController alloc] init]; //a local var gives same results. 

    self.myModalVC.dismissDelegate = self; //the delegate is handled as proper. 

    UINavigationController *navController = [[UINavigationController alloc] 
              initWithRootViewController:self.myModalVC]; 

    //navController.modalPresentationStyle = UIModalPresentationFormSheet; 

    [self presentModalViewController:navController animated:YES]; 

    [self.myModalVC release]; 
    [navController release]; 
} 

什么可能是一个ModalVC不弹出我的当前视图从哪里它被称为的原因?

我一直在使用这个非常相同的方法(在其他上下文中的其他项目),所以我很眩目它还没有工作。该方法被解雇,它传递的每一行代码都没有崩溃。

如果你有一个想法。张贴在这里。 谢谢。

-(void)showModalVC 
{ 
    self.myModalVC = [[ModalVC alloc] init]; 

    self.myModalVC.dismissDelegate = self; 

    UINavigationController *navController = [[UINavigationController alloc] 
              initWithRootViewController:self.myModalVC]; 

    navController.modalPresentationStyle = UIModalPresentationFormSheet; //or something similar, this one is used on an iPad 

    UILabel *navTopItemTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 44)]; 
    navTopItemTitle.text = @"Modal shizzle"; 
    navTopItemTitle.backgroundColor = [UIColor clearColor]; 
    navTopItemTitle.textColor = [UIColor whiteColor]; 
    navTopItemTitle.textAlignment = UITextAlignmentCenter; 

    [navController.navigationBar.topItem setTitleView:navTopItemTitle]; 

    [self presentModalViewController:navController animated:YES]; 

    [self.addTabViewController release]; 
    [navController release]; 
} 

问题解决了。

我想到的第一件事是,你在这行创建泄露对象:

self.myModalVC = [[MyModalViewController alloc] init]; 

自我。将保留myModalVC,alloc也会保留它,你可能只在dealloc方法中释放它。

在所有其他方式代码看起来相当有用。但看看你是如何使用自我。前缀,也许你的应用程序中有其他地方出现内存问题?尝试阅读有关属性和访问器方法。

+0

感谢您的意见。然而,这不是一个记忆问题。我在函数结尾处释放的alloc以及我的类的dealloc方法中的属性。由于我没有双重免费崩溃或泄漏弹出,我认为我很安全。 –