Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6553045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:32:02+00:00 2026-05-25T12:32:02+00:00

I have set up some code so that when two separate buttons are tapped

  • 0

I have set up some code so that when two separate buttons are tapped on a UIActionSheet, there will be two different actions. Unfortunately nothing happens when the buttons are pressed. The UIActionSheet just unloads as if a cancel button had been pressed.

Here’s my code:

- (IBAction)saveFile:(id)sender {

UIActionSheet *saveFileSheet = [[[UIActionSheet alloc] 
                       initWithTitle:@"iDHSB Download Centre" 
                       delegate:nil 
                       cancelButtonTitle:@"Cancel"  
                       destructiveButtonTitle:nil 
                       otherButtonTitles:@"Download File", @"Show My Files", nil] 
                      autorelease];

 [saveFileSheet showInView:webView];

}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{

NSLog(@"Action Sheet Button Pressed");

if(buttonIndex == 1) {
        NSLog(@"Show My Files");

        [self.window presentModalViewController:savedFiles animated:YES];

}

if(buttonIndex == 2){

        NSLog(@"Saving File");

        // Get the URL of the loaded ressource
        NSURL *theResourcesURL = [[webView request] URL];
        // Get the filename of the loaded ressource form the UIWebView's request URL
        NSString *filename = [theResourcesURL lastPathComponent];
        NSLog(@"Filename: %@", filename);
        // Get the path to the App's Documents directory
        NSString *docPath = [self documentsDirectoryPath];
        // Combine the filename and the path to the documents dir into the full path
        NSString *pathToDownloadTo = [NSString stringWithFormat:@"%@/%@", docPath, filename];


        // Load the file from the remote server
        NSData *tmp = [NSData dataWithContentsOfURL:theResourcesURL];
        // Save the loaded data if loaded successfully
        if (tmp != nil) {
            NSError *error = nil;
            // Write the contents of our tmp object into a file
            [tmp writeToFile:pathToDownloadTo options:NSDataWritingAtomic error:&error];
            if (error != nil) {
                UIAlertView *filenameErrorAlert = [[UIAlertView alloc] initWithTitle:@"Error Saving" message:[NSString stringWithFormat:@"The file %@ could not be saved. Please try again.", filename] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [filenameErrorAlert show];
                [filenameErrorAlert release];

                NSLog(@"Failed to save the file: %@", [error description]);
            } else {
                // Display an UIAlertView that shows the users we saved the file :)
                UIAlertView *filenameAlert = [[UIAlertView alloc] initWithTitle:@"File saved" message:[NSString stringWithFormat:@"The file %@ has been saved.", filename] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [filenameAlert show];
                [filenameAlert release];
            }
        } else {

            NSLog(@"Error, file could not be saved");

        }
}

else 

{

    NSLog(@"Error, could not find button index!");

}
}

Thanks,

James

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:32:02+00:00Added an answer on May 25, 2026 at 12:32 pm

    You have set the UIActionSheet delegate to nil. In this context, you want to set it to self.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that produces a set of primary key values that I
I have java script code to set some of the properties of ajax controls.
In a recent project, I have to maintain some PHP code. I set up
I have a set of methods that do some utility work over SQL connection,
I have some code that does custom drawing. Basically it is form fill program
I have seen some code that removes a given layer from it's superlayer by
I'm writing some code that needs to work against an array of different database
I have some MATLAB code I've been working with. There are three sections, say
I have to set some routing rules in my php application, and they should
I have a set of some classes which are all capable of being constructored

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.