fastred / AHKActionSheet

An alternative to the UIActionSheet inspired by the Spotify app.
MIT License
1.16k stars 130 forks source link

Added safer removal of views #7

Closed danielmj closed 10 years ago

danielmj commented 10 years ago

Was crashing when dismissing the view stating attempting to add a 'nil' object to array. This fixed that problem for me.

fastred commented 10 years ago

Thanks! On what version of iOS is this happening? Can you see which view is nil? I'm asking, because I'd like to understand why this bug occurs.

danielmj commented 10 years ago

I am running iOS 8 b4. It occurred when I dismissed the view then attempted to show a new one. I really couldn't figure out much more then that.. Was kind of a bizarre bug. Once I did those nil checks it worked great! Maybe IOS 8 prioritizes things differently? Causing the subviews to be released prematurely?

**edited typo from autocorrect

danielmj commented 10 years ago

Let me run some tests and I'll find out which view is nil

danielmj commented 10 years ago

after adding the following code to dismissView and setting a breakpoint, I discovered that self.window was nil and couldn't be added to an array.

    NSArray* test = @[self.tableView];
    test = @[self.cancelButton];
    test = @[self.blurredBackgroundView];
    test = @[self.window]; //THIS WAS NIL AND CAUSED THE CRASH
fastred commented 10 years ago

I'm sorry, but I can't reproduce this issue on iOS 8b4 (I tested it on iOS Simulator). Can you see if this happens in the example project: https://github.com/fastred/AHKActionSheet/tree/master/AHKActionSheetExample too?

danielmj commented 10 years ago

Ok so I modified the example to look similar to how I was implementing it and managed to reproduce it. In a nutshell, I took the action sheet as a global variable, then attempted to reuse the variable when an item was selected. Check it out:

https://github.com/danielmj/AHKActionSheet/blob/master/AHKActionSheetExample/AHKActionSheetExample/AHKViewController.m

EDIT: I modified the Delete button in the basic example.

fastred commented 10 years ago

Here's how the code works currently: 1) User taps on the button 2) Table view slides below the screen 3) When the animation ends, AHKActionSheetHandler block gets called

You have to remove this line: https://github.com/danielmj/AHKActionSheet/blob/master/AHKActionSheetExample/AHKActionSheetExample/AHKViewController.m#L75 because at this stage the action sheet is already dismissed. self.window is nil and that's why an exception is thrown.

I'll try to improve the documentation and error handling for this case.

danielmj commented 10 years ago

Oh I see now. Well hopefully this pull request helps to identify edge cases. I will make the changes to my code to reflect the proper implementation.

Thanks for your help!