1

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 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.

Community
  • 1
  • 1
Scott H
  • 101
  • 4
  • You have an `imgPicker` ivar but in the `add` method, you declare a _local_ variable of the same name and alloc+init that _local_ variable (not the ivar). Also in `add`, why do you call `[super viewDidLoad];`? –  Feb 15 '11 at 22:01
  • I made the corrections you mentioned above. The local declaration and super viewDidLoad were both left over from previous test to solve the problem. Unfortunately fixing those did not solve the issue. – Scott H Feb 15 '11 at 23:54
  • @aBitObvious Thank you for leading me to the answer. The local override turned out to be the answer but not on imgPicker but on newNavController. So you lead me to the answer. If you want to put it in as an answer not a comment you earned it. – Scott H Feb 16 '11 at 13:13
  • 1
    Glad you were able to solve it and thanks for the offer but I think you're the right one to give the answer on this one. I completely missed the other variable. –  Feb 16 '11 at 13:45

1 Answers1

1

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

Thanks again!

Scott H
  • 101
  • 4