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

  • SEARCH
  • Home
  • 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 7368027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:36:45+00:00 2026-05-29T03:36:45+00:00

When we try to access the camera, we get a UIActionView , where it

  • 0

When we try to access the camera, we get a UIActionView, where it will say if you want to access the camera, or the album, or cancel.

My code works perfectly but when i click on the cancel button, it takes like 30 seconds to cancel. And i have not written any code inside the cancel method. I simply left it empty.

Why is this delay ? and how can i prevent it ?

code

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

    imagePicker = [[UIImagePickerController alloc] init];

    [imagePicker setDelegate:self];

    if (buttonIndex == 0) {


        [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];

        [self.navigationController presentModalViewController:imagePicker animated:YES]; 

    } else if (buttonIndex == 1) {


        [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];

        [self.navigationController presentModalViewController:imagePicker animated:YES];

    } else {



    } 

}
  • 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-29T03:36:46+00:00Added an answer on May 29, 2026 at 3:36 am

    If you are running this code connected up to Xcode (i.e. it is running in the debugger) then you will be getting a pause as it tries to allocate the UIImagePickerController. This is very slow in the debugger. Try running not plugged in and it should be faster, Also try not to init it unless you need it.

    It might seem bad to repeat the code but you can probably help this by putting:

    imagePicker = [[UIImagePickerController alloc] init];
    [imagePicker setDelegate:self];
    

    inside the if statement.

    Hope this helps 🙂

    Try this:

    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
        if (buttonIndex == 0) {
            imagePicker = [[UIImagePickerController alloc] init];
            [imagePicker setDelegate:self];
            [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
            [self.navigationController presentModalViewController:imagePicker animated:YES]; 
        } else if (buttonIndex == 1) {
            imagePicker = [[UIImagePickerController alloc] init];
            [imagePicker setDelegate:self];
            [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
            [self.navigationController presentModalViewController:imagePicker animated:YES];
        } else {
            // Cancel button code here
        }
    }
    

    This does it a slightly different way

    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex != actionSheet.cancelButtonIndex) {
        imagePicker = [[UIImagePickerController alloc] init];
        [imagePicker setDelegate:self];
        if (buttonIndex == 0) {
            [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
            [self.navigationController presentModalViewController:imagePicker animated:YES]; 
        } else if (buttonIndex == 1) {
            [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
            [self.navigationController presentModalViewController:imagePicker animated:YES];
        }
    } else {
        // Cancel button code goes here
    }
    

    }

    So we first check that it’s not the cancel button, if not we create the UIImagePickerController, then use it in the two cases where it is required. If it i the cancel button then it just does nothing.

    That should look a bit happier.

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

Sidebar

Related Questions

when i try access my webapplication with link http://localhost:8080/MyWebApp/login.do It works fine but when
I get this wired error only when I try to access the web page
I try to access some values in a NSMutableArray I created, but I only
When I try to access a public folder using Session.GetFolderFromPath I get an error
I get an UnauthorizedAccessException everytime I try to access (just read ) a file
I get a green screen with the front camera from samsung galaxy s, but
Hi guys I am using the following code to access Camera from my application
when i try to access the ui from outside the constructor i get a
I try to access information from Twitter and I followed this link: http://code.google.com/p/sociallib/wiki/SocialLibGuide I
I try to access sms db file in xcode but fail. I know its

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.