2011-11-04 84 views
0

我有這個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不彈出我的當前視圖從哪裏它被稱爲的原因?

我一直在使用這個非常相同的方法(在其他上下文中的其他項目),所以我很眩目它還沒有工作。該方法被解僱,它傳遞的每一行代碼都沒有崩潰。

如果你有一個想法。張貼在這裏。 謝謝。

回答

0
-(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]; 
} 

問題解決了。

0

我想到的第一件事是,你在這行創建泄露對象:

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

自我。將保留myModalVC,alloc也會保留它,你可能只在dealloc方法中釋放它。

在所有其他方式代碼看起來相當有用。但看看你是如何使用自我。前綴,也許你的應用程序中有其他地方出現內存問題?嘗試閱讀有關屬性和訪問器方法。

+0

感謝您的意見。然而,這不是一個記憶問題。我在函數結尾處釋放的alloc以及我的類的dealloc方法中的屬性。由於我沒有雙重免費崩潰或泄漏彈出,我認爲我很安全。 –