我为UIAlertView
创建了类别,并且重写了委托方法willPresentAlertView
,但是我的方法没有被激发。如何覆盖类别中的委托方法?
示例代码:
@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
为什么你想要它在一个类别?什么目的? –
委托方法从委托对象运行,源对象hav只启动将以委托对象需要的方式执行的方法。如果你想要额外的功能,你可以把它写在类别或子类中。如果你想实现委托方法,你可以在委托对象的类中完成。 –
您是否将警报视图设置为其自己的代理? – jrturton