2011-08-28 33 views
0

我正在調用一個包含在控制器類中的方法,該方法必須更改視圖。它在insertsubview.view上產生一個錯誤。如何解決它?感謝您從當前menuViewController類來自另一個類的調用方法在xcode上產生SIGABRT錯誤

電話:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    aboutTabController * myObject = [[aboutTabController alloc] init]; 

    if (indexPath.section == 1) { 

     switch (indexPath.row) { 
      case 0: 
       [myObject turnIdioma]; 
       break; 
      case 1: 
       // 
       break; 
      default: 
      break;} 
    } 

} 

//method implememented in controller class: 

- (void) turnIdioma 
{ 


    [UIView beginAnimations:@"View Flip" context:nil]; 
     [UIView setAnimationDuration:1.0]; 
     [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; 
    if (self.controladorAjustes == nil) 
    { 
     settingsViewController *aController = [[settingsViewController alloc] initWithNibName:@"mailViewController" bundle:nil]; 
     self.controladorAjustes = aController; 
     [aController release]; 
    } 

    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; 

    [self.controladorMenu viewWillDisappear:YES]; 
    [self.controladorAjustes viewWillAppear:YES]; 

    [self.controladorMenu.view removeFromSuperview]; 
    [self.view insertSubview:controladorAjustes.view atIndex:0]; 

    [self.controladorMenu viewDidDisappear:YES]; 
    [self.controladorAjustes viewDidAppear:YES]; 

    [UIView commitAnimations]; 
} 
+0

在將它作爲子視圖插入之前,請檢查controladorAjusted.view的值。它可能是零嗎? –

+0

是的,它是零。方法執行時,必須移除調用該方法的類的視圖,這是否會成爲問題? – Ruth85

+0

好的,解決了,只是在調用xib的時候!名字不正確。謝謝。 – Ruth85

回答

0

您不能插入重視對象作爲一個子視圖一個零。通常情況下,視圖控制器將確保在您嘗試獲取其視圖屬性時創建它,並使用適當的方法,具體取決於它是否是由NIB文件定義的視圖。

如果你正在做一些明確的設置視圖爲零,那麼你可能沒有采取正確的做法。我懷疑你正在做一些可疑的內容,請致電:

[self.controladorAjustes viewWillAppear:YES];