【问题标题】:Autorelease of viewcontroller object create application crash, with error of EXC_BAD_EXCESS视图控制器对象的自动释放导致应用程序崩溃,错误为 EXC_BAD_EXCESS
【发布时间】:2013-11-07 03:44:15
【问题描述】:

提前致谢,在我的应用程序中,我尝试使用 tableviewdidselectrowatindexpath 方法显示第二个视图控制器。下面是我的代码,如果我不使用自动释放它可以正常工作,但是如果我使用自动释放它会给出错误,我尝试使用NSZombie Enable 来查找错误,它给出了一些关于这个自动释放的错误.我在同一项目的其他类文件中使用的方法相同,但那时它工作正常。

- (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 Dance Program[3855:a0b] * -[AppDelegate performSelector:withObject:withObject:]:消息发送到已释放实例 0xa077590

【问题讨论】:

  • 哪行代码给你错误?
  • 它在 CreateMessageMainViewController 中按下返回按钮后会发生崩溃。返回按钮的编码如下 -(IBAction)ClickToBack:(id)sender { [self.navigationController popViewControllerAnimated:YES]; }
  • @Kreiri :我编辑了我的 que nd 列出的错误,我通过 NSZombie Enable 得到了。

标签: ios objective-c autoresize


【解决方案1】:

当我最近遇到类似问题时,最适合我的是以下几点:

在 Project->Edit Active Executable -> Arguments tab -> Environment variables 部分下,我添加了以下变量并将其设置为 YES:NSAutoreleaseFreedObjectCheckEnabled、NSZombieEnabled 和 NSDebugEnabled。

在 Run 菜单下,我选择了 Enable Guard Malloc。

通过这些设置,调试器提供了更多关于我的代码有什么问题的提示。

我找到了这些提示Here

同时查看此链接ViewController respondsToSelector: message sent to deallocated instance (CRASH)

祝你好运……

【讨论】:

  • 谢谢.. 抱歉回复晚了.. 对于这个问题,我暂时尝试了以下解决方案。我在 CreateMessageMainViewController 中导入 CreateMessageViewController.h 文件,并在 .h 文件中创建它的对象。比只是将对象释放部分放在 -(void)dealloc 方法中做同样的事情。那东西现在可以用了..
猜你喜欢
  • 1970-01-01
  • 2011-12-31
  • 2011-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-23
相关资源
最近更新 更多