I have created category for UIAlertView and overridden the delegate method willPresentAlertView but my method in the category not getting fired.
sample code :
@interface UIAlertView (CustomAlert)
@end
@implementation UIAlertView (CustomAlert)
- (void)willPresentAlertView:(UIAlertView *)alertView1
{
for (UIView *sub in [alertView1 subviews])
{
if([sub class] == [UIImageView class])
{
((UIImageView *)sub).image=nil;
((UIImageView *)sub).backgroundColor = [UIColor blackColor];
}
}
[alertView1.layer setBorderColor:[[UIColor whiteColor] CGColor]];
[alertView1.layer setCornerRadius:0];
[alertView1.layer setBorderWidth:2];
}
@end
If your intent is providing a default implementation for
willPresentAlertViewdelegate method, then your approach (definingwillPresentAlertViewin aUIAlertViewcategory) is correct. You only need to pass the alert itself as a delegate so that the method is called:If you do not do that, your delegate method will not be called.
On the other hand, I doubt that defining a default implementation like that is really of great use, since in principle each alert would need its own specific delegate method.