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 6913997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:17:27+00:00 2026-05-27T09:17:27+00:00

This is my code to present the UIImagePickerController: // Show the media browser with

  • 0

This is my code to present the UIImagePickerController:

// Show the media browser with our settings, then the browser will call our delegate if needed
- (BOOL) startMediaBrowserFromViewController: (UIViewController*) controller
                               usingDelegate: (id <UIImagePickerControllerDelegate,
                                               UINavigationControllerDelegate>) delegate {

    if (([UIImagePickerController isSourceTypeAvailable:
          UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)
        || (delegate == nil)
        || (controller == nil))
        return NO;

    UIImagePickerController *mediaUI = [[[UIImagePickerController alloc] init] autorelease];
    mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    // Check for images type
    NSArray * availableTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
    BOOL imgsOnlyAvailable = NO;
    // Check if we have only images 
    for (int i = 0; i < [availableTypes count]; i++) {
        // Convert the type
        CFStringRef type = (CFStringRef) [availableTypes objectAtIndex:i];
        if (CFStringCompare ((CFStringRef) type, kUTTypeImage, 0) == kCFCompareEqualTo) {
            // We have images
            imgsOnlyAvailable = YES;
            break;
        }
    }

    // Check if they are available
    if (imgsOnlyAvailable == NO) 
        return NO;

    // Displays only saved pictures from the Camera Roll album.
    mediaUI.mediaTypes = [NSArray arrayWithObject:(id) kUTTypeImage];

    // Hides the controls for moving & scaling pictures, or for
    // trimming movies. To instead show the controls, use YES.
    mediaUI.allowsEditing = NO;

    mediaUI.delegate = delegate;

    [controller presentModalViewController: mediaUI animated: YES];
    return YES;
}

// Picker delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
    UIImage *originalImage;

    // Handle a still image picked from a photo album
    if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0)
        == kCFCompareEqualTo) {

        originalImage = (UIImage *) [info objectForKey:
                                     UIImagePickerControllerOriginalImage];    
        // Set image
        self.imgPic.image = originalImage;

        // Now set the button to enabled
        self.btnToText.enabled = YES;
    }

    // Hide picker selector
    [[picker parentViewController] dismissModalViewControllerAnimated: YES];
    [picker release];
}

The problem is whenever I try to click an image in the UIImagePickerController nothing happens (usually it chooses the image then will dismiss the Controller)

Is there any reason why things are going wrong like this?

Thanks!

// Select the image
- (IBAction)btnSelectFileTouchUp:(id)sender {

    // Start the media browser
    if ([self startMediaBrowserFromViewController:self usingDelegate:self] == NO) {
        // Can't open the media browser
        UIAlertView * alrt = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Can't open the photo media browser in this device" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [alrt show];
        [alrt release];
    }
}
  • 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-27T09:17:28+00:00Added an answer on May 27, 2026 at 9:17 am

    Check out the documentation for parentViewController in the UIViewController Class Reference. Specifically this little tidbit.

    Prior to iOS 5.0, if a view did not have a parent view controller and
    was being presented modally, the view controller that was presenting
    it would be returned. This is no longer the case. You can get the
    presenting view controller using the presentingViewController
    property.

    In this instance, I expect that parentViewController is nil on iOS 5 and that is why the controller will not dismiss. Try replacing parentViewController with presentingViewController.

    Update: You’ll have to check for the existence of presentingViewController on UIViewController to provide behavior for iOS versions < 5.0.

    UIViewController *dismissingController = nil;
    
    if ([self respondsToSelector:@selector(presentingViewController)])
        dismissingController = self.presentingViewController;
    else
        dismissingController = self.parentViewController;
    
    [dismissingController dismissModalViewControllerAnimated:YES];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, this question is best explained in code. So will try to present the
I am using this code to check that array is present in the HashMap
I'm trying to present a UIImagePickerController from a UITableViewController subclass using the following code:
I have a code for UIImage picker photoImagePicker=[[UIImagePickerController alloc]init]; photoImagePicker.delegate=self; photoImagePicker.sourceType=UIImagePickerControllerSourceTypeCamera; photoImagePicker.mediaTypes=[UIImagePickerController availableMediaTypesForSourceType:photoImagePicker.sourceType]; [self
I'm drawing an xna project on a winforms Control using the following code: this.GraphicsDevice.Present(MainForm.GamePanelHandle);
Is there a better way to present this code? while (vIter.hasNext()) { Long actId
I have this code to present images: <?php foreach ($images as $row) : ?>
I need this code to, if #vid is present, add 855px to its current
This code in JS gives me a popup saying i think null is a
This code is from Prototype.js . I've looked at probably 20 different tutorials, and

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.