开发者

Opening UIImagePickerController from within modal view controler

开发者 https://www.devze.com 2023-02-11 10:30 出处:网络
I am trying to present a image selector to my user while they are on a view presented as modal view.

I am trying to present a image selector to my user while they are on a view presented as modal view.

I am building the view in a table view app. Right now the code runs but does not open the ImagePicker.

In DetailTableViewController.m

@implementation DetailTableViewController

There is an (+) button in the nav and when it is clicked I call

- (void)add
{
  DetailTableViewController *controller = [[DetailTableViewController alloc]
                                  initWithStyle:UITableViewStyleGrouped];    

UINavigationController *newNavController = [[UINavigationController alloc]
                                            initWithRootViewController:controller];
newNavController.delegate = self;

[[self navigationController] presentModalViewController:newNavController
                                               animated:YES];

DetailTableViewController *controller2 = [[DetailTableViewController alloc]
                                         initWithStyle:UITableViewStyleGrouped];    
imgPicker = [[UIImagePickerController alloc]
                                      initWithRootViewController:controller2];
imgPicker.allowsEditing = YES;
imgPicker.delegate = self;      

//______________HERE I CREATE THE INTERFACE FOR开发者_StackOverflow社区 THIS VIEW IN CODE__________________

    NSLog(@"Load add View");
 }

One of the button on this page is a select image button which is here:

   - (IBAction)grabImage {
        [newNavController pushViewController:imgPicker animated:YES];
    NSLog(@"grabImage");
    }

This does not present the imgPicker view. But the button click is logged.

I have in the top of file: DetailTableViewController.m

@implementation DetailTableViewController

@synthesize imgPicker;

In DetailTableViewController.h

 @interface DetailTableViewController : UITableViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextViewDelegate> {
    MWFeedItem *item;
    NSString *dateString, *summaryString;
    IBOutlet UIWebView *webview;
    IBOutlet UIButton *dismissViewButton;
    UIImagePickerController *imgPicker;
    UINavigationController *newNavController;
    IBOutlet UIButton *upload;
    IBOutlet UIButton *doneEdit;
    IBOutlet UIImageView *image;
}

How can I make the imgPicker display? I have tried:

  • using presentModalViewController instead of push in grabImage
  • List item many combinations of which controller imgPicker is presented to. With some I get the error: (Application tried to present a nil modal view controller on target)
  • several variations from this question:

    iPhone modal view inside another modal view?

UPDATED including corrections from @aBitObvious, but the issue remains.


@aBitObvious pointed me to the answer. The local override turned out to be the answer but not on imgPicker but on newNavController.

Thanks again!

0

精彩评论

暂无评论...
验证码 换一张
取 消