viewcontroller对象的自动释放创建应用程序崩溃,错误为EXC_BAD_EXCESS

时间:2013-10-28 11:29:14

标签: ios objective-c autoresize

在此先感谢,在我的应用程序中,我尝试使用tableviewdidselectrowatindexpath方法显示第二个视图控制器。下面是我的代码,如果我不使用自动释放它的工作正常,但如果我使用autorelease它给出错误,我尝试使用NSZombie启用查找错误,它给出一些错误这个Autorelease。我在同一个项目的其他类文件中使用的方法相同,但那时它工作正常。

- (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

1 个答案:

答案 0 :(得分:0)

最近我遇到类似问题时最适合我的是:

在项目下 - >编辑活动可执行文件 - >参数选项卡 - >环境变量部分我添加并设置为YES以下变量:NSAutoreleaseFreedObjectCheckEnabled,NSZombieEnabled和NSDebugEnabled。

在“运行”菜单下,我选择了“启用Guard Malloc”。

通过这些设置,调试器提供了有关我的代码错误的更多提示。

我找到了这些提示Here

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

祝你好运......

相关问题