2013-10-28 53 views
1

在此先感謝,在我的應用程序中,我試圖用tableviewdidselectrowatindexdex方法顯示第二個視圖控制器。下面是我的代碼,它的工作正常,如果我不使用autorelease,但如果我使用autorelease它給出錯誤,我試過使用NSZombie啓用發現錯誤,它給這個Autorelease一些錯誤。我在同一個項目的其他類文件中使用了同樣的方法,但是那個時候它正常工作。自動釋放viewcontroller對象創建應用程序崩潰,錯誤爲EXC_BAD_EXCESS

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
    { 
    if ([[UIScreen mainScreen] bounds].size.height == 568) 
    { 
     CreateMessageViewController *cvc = [[[CreateMessageViewController alloc]initWithNibName:@"CreateMessageViewController"bundle:nil]autorelease]; 
     cvc.Username = [arrayUserName objectAtIndex:indexPath.row]; 
     cvc.UserId = [arrayUserID objectAtIndex:indexPath.row]; 
     cvc.isGroup = @"no"; 
     [self.navigationController pushViewController:cvc animated:YES]; 


    } 

    else 
    { 

     CreateMessageViewController *cvc = [[[CreateMessageViewController alloc]initWithNibName:@"CreateMessageViewControlleriPhone4"bundle:nil]autorelease]; 
     cvc.Username = [arrayUserName objectAtIndex:indexPath.row]; 
     cvc.UserId = [arrayUserID objectAtIndex:indexPath.row]; 
     cvc.isGroup = @"no"; 
     [self.navigationController pushViewController:cvc animated:YES]; 

    } 

} 
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{ 
    CreateMessageViewController *cvc = [[[CreateMessageViewController alloc]initWithNibName:@"CreateMessageViewControlleriPad"bundle:nil]autorelease]; 
    cvc.Username = [arrayUserName objectAtIndex:indexPath.row]; 
    cvc.UserId = [arrayUserID objectAtIndex:indexPath.row]; 
    cvc.isGroup = @"no"; 
    [self.navigationController pushViewController:cvc animated:YES]; 

} 

} 

與我在其他類文件中使用的方法相同,但是不會給出任何錯誤或崩潰,該代碼如下所示。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    if (StudioManger) 
{ 

    NSLog(@"You can edit Schedule"); 
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
    { 
     if ([[UIScreen mainScreen] bounds].size.height == 568) 
     { 
      EditScheduleViewController *esvc = [[[EditScheduleViewController alloc]initWithNibName:@"EditScheduleViewController" bundle:Nil]autorelease]; 
      esvc.StudioID = myStudioID ; 
      esvc.Fromtime = [arrayfromtime objectAtIndex:indexPath.row]; 
      esvc.Totime = [arraytotime objectAtIndex:indexPath.row]; 
      esvc.Date = [arraydate objectAtIndex:indexPath.row]; 
      esvc.Grouptype = [arraygroupname objectAtIndex:indexPath.row]; 
      esvc.DanceType = [arraydancetype objectAtIndex:indexPath.row]; 
      esvc.Day = [arrayDay objectAtIndex:indexPath.row]; 
      esvc.scheduleid = [arrayScheduleID objectAtIndex:indexPath.row]; 
      esvc.StudioName = StudioName ; 
      [self.navigationController pushViewController:esvc animated:YES]; 

     } 

     else 
     { 
      EditScheduleViewController *esvc = [[[EditScheduleViewController alloc]initWithNibName:@"EditScheduleViewControlleriPhone4" bundle:Nil]autorelease]; 
      esvc.StudioID = myStudioID ; 
      esvc.Fromtime = [arrayfromtime objectAtIndex:indexPath.row]; 
      esvc.Totime = [arraytotime objectAtIndex:indexPath.row]; 
      esvc.Date = [arraydate objectAtIndex:indexPath.row]; 
      esvc.Grouptype = [arraygroupname objectAtIndex:indexPath.row]; 
      esvc.DanceType = [arraydancetype objectAtIndex:indexPath.row]; 
      esvc.Day = [arrayDay objectAtIndex:indexPath.row]; 
      esvc.scheduleid = [arrayScheduleID objectAtIndex:indexPath.row]; 
      esvc.StudioName = StudioName ; 
      [self.navigationController pushViewController:esvc animated:YES]; 


     } 

    } 
    else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    { 
     EditScheduleViewController *esvc = [[[EditScheduleViewController alloc]initWithNibName:@"EditScheduleViewControlleriPad" bundle:Nil]autorelease]; 
     esvc.StudioID = myStudioID ; 
     esvc.Fromtime = [arrayfromtime objectAtIndex:indexPath.row]; 
     esvc.Totime = [arraytotime objectAtIndex:indexPath.row]; 
     esvc.Date = [arraydate objectAtIndex:indexPath.row]; 
     esvc.Grouptype = [arraygroupname objectAtIndex:indexPath.row]; 
     esvc.DanceType = [arraydancetype objectAtIndex:indexPath.row]; 
     esvc.Day = [arrayDay objectAtIndex:indexPath.row]; 
     esvc.scheduleid = [arrayScheduleID objectAtIndex:indexPath.row]; 
     esvc.StudioName = StudioName ; 
     [self.navigationController pushViewController:esvc animated:YES]; 

     } 

    } 
    else 
    { 

    } 


    } 

請幫我一下, 請注意,我沒有使用ARC。而在Xcode 5

錯誤我通過NSZombie獲得工作是如下,

2013年10月28日17:12:34.287舞蹈課程[3855:A0B] * - [AppDelegate的performSelector:withObject: withObject:]:消息發送到釋放實例0xa077590

+0

給你錯誤哪一行代碼? – Kreiri

+0

在CreateMessageMainViewController中按下按鈕後,它會給出確切的結果。後退按鈕的編碼如下 - (IBAction)ClickToBack:(id)發件人 {self.navigationController popViewControllerAnimated:YES]; } – zak

+0

@Kreiri:我編輯了我的問題列出的錯誤,我通過NSZombie啓用。 – zak

回答

0

對我來說,當我遇到了類似的問題,什麼工作最好近日被以下幾點:

在項目 - 下>編輯主動可執行文件 - >參數選項卡 - >環境變量部分我添加並設置爲YES以下變量:NSA utoreleaseFreedObjectCheckEnabled,NSZombieEnabled和NSDebugEnabled。

在Run菜單下,我選擇了Enable Guard Malloc。

使用這些設置,調試器爲我的代碼提供了更多提示。

我發現這些提示Here

而且還要檢查這個環節ViewController respondsToSelector: message sent to deallocated instance (CRASH)

好運...

+0

謝謝..抱歉,對於遲到的答覆..對於這個問題暫時我嘗試了下面的解決方案。 我在CreateMessageMainViewController中導入CreateMessageViewController.h文件,並在.h文件中創建它的對象。比起同樣的事情只是把這個對象釋放部分放在 - (void)dealloc方法中。那東西現在可以工作了.. – zak

相關問題