Skip to content

Instantly share code, notes, and snippets.

@felixflores
Last active December 10, 2015 00:48
Show Gist options
  • Save felixflores/4353703 to your computer and use it in GitHub Desktop.
Save felixflores/4353703 to your computer and use it in GitHub Desktop.
Make Action Sheet a little bit more sane
//
// UIViewController+ActionSheet.h
// Tweaks
//
// Created by Felix Flores on 12/21/12.
// Copyright (c) 2012 felixflor.es. All rights reserved.
//
#import <UIKit/UIKit.h>
@protocol FFActionSheetDelegate <UIActionSheetDelegate>
@optional
- (void)actionSheetAction__ActionSheetTitle__:(UIActionSheet *)actionSheet clickedButtonWithTitle:(NSString *)buttonTitle;
@end
@interface UIViewController (ActionSheet)
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
@end
//
// UIViewController+ActionSheet.m
// Tweaks
//
// Created by Felix Flores on 12/21/12.
// Copyright (c) 2012 felixflor.es. All rights reserved.
//
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
#import "UIViewController+ActionSheet.h"
@implementation UIViewController (ActionSheet)
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *actionSheetTitle = [actionSheet title];
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
NSString *selectorString = [NSString stringWithFormat:@"actionSheet%@:clickedButtonWithTitle:", actionSheetTitle];
SEL selector = NSSelectorFromString(selectorString);
if ([self respondsToSelector:selector]) {
[self performSelector:selector withObject:actionSheetTitle withObject:buttonTitle];
}
}
#pragma clang diagnostic pop
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment