-2

I have two ViewControllers. Let's call them no1 and no2. In no2 I have PopoverViewController with some options and instance of NSTimer. Timer function is calling popToViewController 3 seconds after popup is presented if nothing is clicked in the popover, which is returning user to no1 ViewController. Problem is when this function is triggered, screen is changed to the no1, but application crashes without error message below.

PopoverViewController doesn't have delegate and it is registered as property of second VC as:

@property (nonatomic)UIPopoverController *optionsPopover;

Does anyone have any idea why there is no crash report available? And if there is no reference to the popover why it is crashing?

Implementation in viewWillDisappear looks like this:

if([_optionsPopover isPopoverVisible]){
    [_optionsPopover dismissPopoverAnimated:NO];
    _optionsPopover = nil;
}

I tried forcing UI to update on main thread (below code), but the result is the same. Crash still exists.

dispatch_async(dispatch_get_main_queue(), ^{
    if([_optionsPopover isPopoverVisible]){
        [_optionsPopover dismissPopoverAnimated:NO];
        _optionsPopover = nil;
    }
});
AleksandarNS
  • 265
  • 1
  • 2
  • 15

3 Answers3

1

Please try to make strong reference of UIPopoverController

@property (nonatomic,retain)UIPopoverController *optionsPopover;

call below method in - (void)viewDidDisappear:(BOOL)animated instead of viewwilldisappear -

- (void)viewDidDisappear:(BOOL)animated {
if([_optionsPopover isPopoverVisible]){
    [_optionsPopover dismissPopoverAnimated:NO];
    _optionsPopover = nil;
}
}
Santu C
  • 2,644
  • 2
  • 12
  • 20
  • I did that, but error is still present, and information about crash doesn't exist. – AleksandarNS May 28 '15 at 07:28
  • I don't get one. That is the main issue. Application crashes, and only shows marked green line in main class. – AleksandarNS May 28 '15 at 09:42
  • Please this url which help to get the line where its crash - http://stackoverflow.com/questions/7703052/xcode-doesnt-show-the-line-that-causes-a-crash – Santu C May 28 '15 at 09:47
  • I get this error *** -[_UIPopoverView layer]: message sent to deallocated instance 0x127d8da20 – AleksandarNS May 28 '15 at 10:27
  • Ok got your problem, Please check above – Santu C May 28 '15 at 11:16
  • This solved my problem, but now I get UI component in previous VC for 1 second, and then it is dismissed. Is there any way that component is removed without displaying it in wrong window? viewWillDissappear was responsible for that. – AleksandarNS May 28 '15 at 11:36
0

You are setting _optionsPopover to nil after dismiss..

Edit

Possible problem: timer not invalidated after viewController is dismissed,

if([_optionsPopover isPopoverVisible])
{
    [yourTime invalidate]; // added on edit
    [_optionsPopover dismissPopoverAnimated:NO];
}

Try: [_optionsPopover dismissPopoverAnimated:NO]; alone, because dismissing it will basically makes it nil..

0yeoj
  • 4,500
  • 3
  • 23
  • 41
  • How can you call something from object, if you previously set reference to an object to be nil? By doing this, you are calling function on null pointing reference. – AleksandarNS May 27 '15 at 13:54
  • I tried this, but error is present still. App crashes without information about crash. I have NSZombie added to project. – AleksandarNS May 28 '15 at 07:28
  • have you `- invalidate` your timer before this? it's also possible that the timer is triggered.. and you've dismissed the viewcontroller where the target method is.. – 0yeoj May 28 '15 at 08:47
  • Timer is triggered only once when time expires. I am not calling invalidate at any point, except when option from popover is clicked. Option is never clicked, and I breakpointet that like, which is never called. – AleksandarNS May 28 '15 at 09:45
  • its hard to breakpoint timer with interval.. >.< anyway try calling invalidate.. are you afraid to try things out? you wont figure out what's wrong without trying.. – 0yeoj May 28 '15 at 09:47
0

Set the property as strong :

@property (strong, nonatomic) UIPopoverController *_optionsPopover;

Remove this line of code :

_optionsPopover = nil;