Show the Pop Over while previous Pop Over still visible cause apps crash?
Hi all,
In my project, when I clicked a Bar Button, a pop over will be displayed, but when I clicked that Bar Button again while the previous pop over still visible, it cause the application crash. Below is my code that show the pop over when click on Bar Button:
After I do some survey, I found that may be I need to do some checking using isPopoverVisible property when need display pop over. But I hope I can find out why my application crashed just now? Anyone know what cause the above case occur?
Any comments and ideas are welcome and appreciated. Thanks a lot.
I thought the Apple interface guidelines noted that if a popover was being displayed already that pressing the bar button should do Nothing. This is what you should probably code for.
So if the popover controller is nil, then create it. Otherwise do nothing.
In the console not have crash message. What happened is in the console there state "sharedlibrary apply-load-rules all (gdb) " and then in XCode, it jumps to the code inside main.m and display a message " Thread 1: Problem received signal: "SIGABRT". "
I thought the Apple interface guidelines noted that if a popover was being displayed already that pressing the bar button should do Nothing. This is what you should probably code for.
So if the popover controller is nil, then create it. Otherwise do nothing.
Hi,
Yes, at first I also display pop over by checking whether the pop over is nil. So, at that time I reset the popover controller back to nil inside popoverControllerDidDismissPopover method. But I have two bar buttons that used to pop up two different pop over controller in same interface. So, I face a problem in a case below:
- When I click both bar buttons, both pop overs will be displayed.
- Then, when I clicked outside the pop over views to dismiss the pop over, both pop over controllers set back to nil but what happens in interface is it just dismiss one of the pop overs.
- So, when I click the bar button again ( the bar button with the pop over still visible), since its pop over controller is set to nil already, it recreate and represent it and cause my app crash. But this time the crash message become "Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.".
So, when I display the pop overs by checking "isPopoverVisible" property, it seems can solved the problem... But am I using a correct way to solve the problem? Do you have any ideas on this?
I thought you were having the issue with one popover. I don't know the proper way to have two bar button items with two popover views.
I would think to dismiss one before the other one opens. Maybe someone else encountered this issue before. I would be interested in their approach.
Quote:
Originally Posted by cthesky
Hi,
Yes, at first I also display pop over by checking whether the pop over is nil. So, at that time I reset the popover controller back to nil inside popoverControllerDidDismissPopover method. But I have two bar buttons that used to pop up two different pop over controller in same interface. So, I face a problem in a case below:
- When I click both bar buttons, both pop overs will be displayed.
- Then, when I clicked outside the pop over views to dismiss the pop over, both pop over controllers set back to nil but what happens in interface is it just dismiss one of the pop overs.
- So, when I click the bar button again ( the bar button with the pop over still visible), since its pop over controller is set to nil already, it recreate and represent it and cause my app crash. But this time the crash message become "Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.".
So, when I display the pop overs by checking "isPopoverVisible" property, it seems can solved the problem... But am I using a correct way to solve the problem? Do you have any ideas on this?