Action sheet

Send Snippet To: Save this snippet to Code Collector Pro -- view all balzan's snippets
language: Objective-C
license: Other

Code for Snippet:

                
////in .h file 
 
//follow 
<UIActionSheetDelegate>
 
 
 
///// in .m file
 
@property (nonatomic, strong) UIActionSheet* actionSheet;
 
 
// print button example
 
- (IBAction)printBarButtonTouched:(id)sender {
    if ([UIPrintInteractionController isPrintingAvailable]) {
        if (!_actionSheet) {	// check that you have not already alloc ed it
            _actionSheet = [[UIActionSheet alloc] initWithTitle:@"Share" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Print", @"Email",  nil];
            [_actionSheet showFromBarButtonItem:self.actionBarButton animated:YES];
 
        }
 
    }
    else{
     	if (!_actionSheet) {	// check that you have not already alloc ed it
            _actionSheet = [[UIActionSheet alloc] initWithTitle:@"Email" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Rundown Summary", @"This Story", @"All Stories", @"Selected Stories", nil];
            [_actionSheet showFromBarButtonItem:self.actionBarButton animated:YES];
        }
    }
}
 
 
 
#pragma mark - UIActionSheet Delegate
 
 
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (actionSheet.cancelButtonIndex != buttonIndex) {
        if ([actionSheet.title isEqualToString:@"Share"]) {
             if (buttonIndex == 0){
 
                _actionSheet = [[UIActionSheet alloc] initWithTitle:@"Print" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Rundown Summary", @"This Story", @"All Stories", @"Selected Stories", nil];
                [_actionSheet showFromBarButtonItem:self.actionBarButton animated:YES];
             }
             else if (buttonIndex == 1){
                 _actionSheet = [[UIActionSheet alloc] initWithTitle:@"Email" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Rundown Summary", @"This Story", @"All Stories", @"Selected Stories", nil];
                 [_actionSheet showFromBarButtonItem:self.actionBarButton animated:YES];
 
             }
        }
 
 
        if ([actionSheet.title isEqualToString:@"Print"] || [actionSheet.title isEqualToString:@"Email"]) {
            NSMutableString* bodyString = [[NSMutableString alloc] init];
            if (buttonIndex == 0){
                // Rundown Summary
 
            }
            else if (buttonIndex == 1) {
 
            }
            else if (buttonIndex == 2){
 
            }
            else if (buttonIndex == 3){
                [self performSegueWithIdentifier:@"selectStoriesPopOver" sender:actionSheet.title];
 
            }   
        }
    }
}
 
// clear it so you can use it again
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
   // NSLog(@"Action Sheet Dissmissed  Title %@", actionSheet.title);
    self.actionSheet = nil;
}
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 465
Date Added: 2013-08-14 05:22:59
Last Modified: 2014-02-18 20:29:30

Web Analytics