简体   繁体   English

无法检测到EKEventEditViewController中的崩溃

[英]unable to detect crash in EKEventEditViewController

when i click on done button at EKEventEditViewController then app gets crashed saying "exc_bad_access".I also used break point to detect it but cannot find it. 当我在EKEventEditViewController上单击完成按钮时,应用程序崩溃并说“ exc_bad_access”。我还使用断点检测到它,但找不到它。 There is nothing about crash in gdb. 关于gdb崩溃没有任何内容。 Where should i check crash. 我应该在哪里检查崩溃。 Done-button do not shift control to EKEventEditViewDelegate - method. 完成按钮不会将控件移至EKEventEditViewDelegate-方法。 It just crash.Help me out plz. 它只是崩溃。请帮我。

here is my code 这是我的代码

-(void)viewWillAppear:(BOOL)animated
{

EKEventEditViewController *addController = [[EKEventEditViewController alloc] 
 initWithNibName:nil bundle:nil];
addController.eventStore = self.eventStore;
addController.event = event;
addController.editViewDelegate = self;
[self presentModalViewController:addController animated:YES]; 
[super viewWillAppear:YES];

}

 #pragma mark - 
 #pragma mark EKEventEditViewDelegate

- (void)eventEditViewController:(EKEventEditViewController *)controller 
      didCompleteWithAction:(EKEventEditViewAction)action {

NSError *error = nil;
EKEvent *thisEvent = controller.event;

switch (action) {

         case EKEventEditViewActionCanceled:    
         break;

    case EKEventEditViewActionSaved:
            [controller.eventStore saveEvent:controller.event  
                    span:EKSpanThisEvent error:&error]; 
        break;

    case EKEventEditViewActionDeleted:
        [controller.eventStore removeEvent:thisEvent span:EKSpanThisEvent 
                     error:&error];
        break;

    default:
        break;
}

[controller dismissModalViewControllerAnimated:YES];
[self backTopreviousController];
}

-(void)backTopreviousController
{
  [self.navigationController popToRootViewControllerAnimated:YES];
 }

exc_bad_access suggests that you're accessing memory that has been deallocated (probably a mememory management problem). exc_bad_access建议您正在访问已释放的内存(可能是内存管理问题)。 These issues are a bit hard to tackle because you might release an object (which you should not) at some point and you only run into a problem a little later when accessing this object. 这些问题有点难以解决,因为您可能会在某个时候释放一个对象(不应该释放),并且仅在稍后访问该对象时遇到问题。

You can try the following: 您可以尝试以下方法:

  1. Click the "Run Button Dropdown" 点击“运行按钮下拉菜单”
  2. From the list choose Profile 从列表中选择Profile
  3. The program "Instruments" should open where you can also choose Zombies 程序“仪器”应打开,您也可以选择“ Zombies
  4. Now you can interact with your app and try to cause the error 现在,您可以与您的应用进行交互,并尝试导致错误
  5. As soon as the error happens you should get a hint on when your object was released and therefore deallocated. 一旦发生错误,您应该获得关于何时释放对象并因此释放对象的提示。

僵尸
(source: dimzzy.com ) (来源: dimzzy.com

Your code is crashing because of the following lines. 由于以下几行,您的代码崩溃了。

[controller dismissModalViewControllerAnimated:YES];
[self backTopreviousController];

either you want to pop or dismiss. 您想弹出或关闭。 But not both. 但不是两个。 It depends how you have called this class. 这取决于您如何调用此类。 Push or presentModal ! 推送或presentModal!

Debug the program after setting a breakpoint at the beginning of eventEditViewController:didCompleteWithAction . eventEditViewController:didCompleteWithAction的开头设置断点后,调试程序。 Once your program reaches the breakpoint execute step by step. 程序到达断点后,请逐步执行。

Doing like this, you will know either: 这样,您将知道:

  1. which statement makes the program crash, or 哪个语句使程序崩溃,或者

  2. that the program crashes before even entering that method. 程序甚至在进入该方法之前就崩溃了。

In case 1, you should inspect each object you send a message to and make sure it has not been deallocated. 在情况1中,您应该检查发送消息的每个对象,并确保没有将其释放。 In case 2, you should inspect the action definition that is associated to the Done button. 在情况2中,您应该检查与“完成”按钮关联的操作定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM