I am trying to write a helper class so that our application supports both UIAlertActionand UIAlertView. However, when writing a method alertView:clickedButtonAtIndex:for UIAlertViewDelegateI ran into this problem: I see no way to execute the code in the handler block UIAlertAction.
I am trying to do this by storing an array UIAlertActionin a propertyhandlers
@property (nonatomic, strong) NSArray *handlers;
and then implement such a delegate:
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIAlertAction *action = self.handlers[buttonIndex];
if (action.enabled)
action.handler(action);
}
However, there is no property action.handleror, as I can see, to get it, since the title UIAlertActionhas only:
NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying>
+ (instancetype)actionWithTitle:(NSString *)title style:(UIAlertActionStyle)style handler:(void (^)(UIAlertAction *action))handler;
@property (nonatomic, readonly) NSString *title;
@property (nonatomic, readonly) UIAlertActionStyle style;
@property (nonatomic, getter=isEnabled) BOOL enabled;
@end
Is there any other way to execute code in a handlerblock UIAlertAction?