Skip to content

Instantly share code, notes, and snippets.

@spraveenk91
Last active August 29, 2015 14:08
Show Gist options
  • Save spraveenk91/be47986e6d9aa5092c92 to your computer and use it in GitHub Desktop.
Save spraveenk91/be47986e6d9aa5092c92 to your computer and use it in GitHub Desktop.
1. FirstViewController will show one ActionSheet and its action perform here by UIActionSheetDelegate. Before, presenting this action sheet i am setting the delegate to my CustomAction class
- (void)cellMenuClicked:(id)sender {
CustomAction *obj = [[CustomAction alloc] init];
obj.delegate = self;
thumbActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:obj cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Add to Watchlist", @"Share", nil];
[thumbActionSheet showInView:[self.view window]];
}
#pragma mark - BaseViewController Delegate
- (void)didSelectActionSheetIndex:(NSString *)actionTitle actionSheetIndex:(NSInteger)index {
// NSLog(@"Text - %@", actionTitle);
switch (index) {
case 0: {
[self performSegueWithIdentifier:@"allmoviesSegue" sender:nil];
}
break;
case 1: {
}
break;
case 2: {
[self performSegueWithIdentifier:@"filterSegue" sender:nil];
}
break;
default:
break;
}
}
2. BaseViewController need to show a ActionSheet by pressing on navigation item and pass the selectedIndex to FirstViewController
- (void)menuMore {
// How to perform actionsheet for BaseView Here
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[self customBarButton:[UIImage imageNamed:@"option"] targetMethod:@selector(showMenuView)]];
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:[[UIBarButtonItem alloc] initWithCustomView:[self customBarButton:[UIImage imageNamed:@"more"] targetMethod:@selector(menuMore)]], FIXED_SPACE, [[UIBarButtonItem alloc] initWithCustomView:[self customBarButton:[UIImage imageNamed:@"searchicon"] targetMethod:@selector(searchPage)]], nil];
}
3. CustomAction class has below code,
CustomAction.h
——————————————
@protocol BaseDelegate <NSObject>
@required
- (void)didSelectActionSheetIndex:(NSString *)actionTitle actionSheetIndex:(NSInteger )index;
@end
@interface CustomAction : NSObject <UIActionSheetDelegate>
@property (nonatomic, strong) id<BaseDelegate> delegate;
@end
CustomAction.m
——————————————
#import "CustomAction.h"
@implementation CustomAction
#pragma mark - UIActionSheet Delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([[self delegate] respondsToSelector:@selector(didSelectActionSheetIndex:actionSheetIndex:)]) {
[[self delegate] didSelectActionSheetIndex:[actionSheet buttonTitleAtIndex:buttonIndex] actionSheetIndex:buttonIndex];
}
}
- (void)actionSheetCancel:(UIActionSheet *)actionSheet {
NSLog(@"Dismissed");
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment