wimagguc / ios-custom-alertview

Custom UIAlertView. Continue adding images and UIViews to dialogs in iOS7+
Other
1.66k stars 394 forks source link

Bad access when using [alert setButtonTitles:NULL]; #32

Closed TomDoes closed 10 years ago

TomDoes commented 10 years ago

I'm using a custom alertView to indicate the loading of a UIWebView but it crashes with a bad access message. Without the setButtonTitles line it works fine.

-(void)webViewDidStartLoad:(UIWebView )webView { alert = [[CustomIOS7AlertView alloc]initWithParentView:self.view]; UIActivityIndicatorView spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0,10,240,100)]; [spinner startAnimating]; UIView demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 240, 100)]; UILabel label =[[UILabel alloc]initWithFrame:CGRectMake(0, -30, 240, 100)];

[demoView addSubview:spinner];
[demoView addSubview:label];
[alert setContainerView:demoView];
[alert setButtonTitles:NULL];

[alert show];

}

wimagguc commented 10 years ago

thanks @TomDoes, which xcode / ios version are you using? is there a difference passing NULL or nil object? (also, i've updated the setButtonTitles function with some more defensive code, which should handle null pointers a bit better. would be fun to chase this down though.)

TomDoes commented 10 years ago

Hey this is in xcode 5 ios 7.0.x tried it on devices and simulator. I figured it might have something to with NULL or nil, however both result in a bad access. I tested your more defensive code and it doesn't fix the BAD ACCESS When i remove the setButtons line it works fine again, but with a close button.

wimagguc commented 10 years ago

getting weirder. if you want, you can try to change the CustomIOS7AlertView's init function to be

buttonTitles = nil;

(instead of buttonTitles = @[@"Close"];), that would do the same as setting it to nil with setButtonTitles. perhaps that gives you more insight in the problem. if not, feel free to share some more code, i'll try to look at it. in private, you can find me on twitter by the @wimagguc handle.)

TomDoes commented 10 years ago

Well, setting buttonTitles = nil in the init fixes the bad access problem.

wimagguc commented 10 years ago

is it an arc project? in any ways, we are using @sythesize for the getters/setters - so if a project clean doesn't solve your problem, please feel free to send some more code. (i tried to run the one you have in place, and it works all fine in emulator and on the device as well.)

TomDoes commented 10 years ago

Yes, it's an arc project. It's weird, for now i'll leave it like this. If I encounter similar problems later on, or the source of the bad access i'll let you know.

Thanks for looking into it!

wimagguc commented 10 years ago

haha no worries. i'll close this for now, but just fire up a new ticket if you have more details on this.