2
votes

My Application is getting crashed with the following error.

-[PreviewViewController applicationWillSuspend]: message sent to deallocated instance 0x1806d9e0

My application have two view controllers one is HomeViewController and other one is PreviewViewController.
In home view controller i am displaying a table view. When selecting the row of table view i am presenting the preview view controller.
I selected one row then preview view controller is presented.

PreviewViewController *previewController = [[PreviewViewController alloc]initWithPreviewImage:[[kfxKEDImage alloc] initWithImage:imgCaptured] withSourceofCapture:_typeOfCapture typeOfDocumentCaptured:PHOTO];
[self presentViewController:previewController animated:YES completion:nil];

Dismissed the preview view controller.

[self dismissViewControllerAnimated:YES completion:nil];

Application goes into background then it is not crashed.
I selected two rows one after another. Application goes into background then it is crashed. I don't know why it is behaving like that. If anyone know the solution please tell me.

Thanks In Advance

2
Can you provide your code for showing preview controller after selecting cell in table & code which gets executed when you click on home button ? Without code its hard to tell you why app is crashing.iOSAppDev
Post code that handles selection, dismissing and presenting view controllers.Rafa de King
I added the code snippets for presenting the preview view controller and dismissing the view controller.MobileDev
Please post the full symbolicated crash report.Kerni

2 Answers

1
votes

I had this problem, it was caused by someone overriding 'dealloc' in a UIViewController category.

1
votes

https://github.com/taphuochai/PHAirViewController/issues/13 @chrishulbert

Remove this:

 - (void)dealloc
 {
      self.phSwipeHander = nil;
 }

Replace dealloc with this:

 /// This is so that phSwipeGestureRecognizer doesn't create a swipe gesture in *every* vc's dealloc.
 - (BOOL)phSwipeGestureRecognizerExists {
     return objc_getAssociatedObject(self, SwipeObject) ? YES : NO;
 }

 - (void)ph_dealloc
 {
     if (self.phSwipeGestureRecognizerExists) {
         self.phSwipeHander = nil;
      }
     [self ph_dealloc]; // This calls the original dealloc.
 }

 /// Swizzle the method into place.
 void PH_MethodSwizzle(Class c, SEL origSEL, SEL overrideSEL) {
     Method origMethod = class_getInstanceMethod(c, origSEL);
     Method overrideMethod = class_getInstanceMethod(c, overrideSEL);
     if (class_addMethod(c, origSEL, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod))) {
         class_replaceMethod(c, overrideSEL, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
     } else {
         method_exchangeImplementations(origMethod, overrideMethod);
     }
 }

 /// Swizzle dealloc at load time.
 + (void)load {
     SEL deallocSelector = NSSelectorFromString(@"dealloc"); // Because ARC won't allow @selector(dealloc).
     PH_MethodSwizzle(self, deallocSelector, @selector(ph_dealloc));
 }