1

In the app I am trying to build, I am trying to use the UIImageController but am running into a bit of a problem. I am not doing this in the ViewController class... Here's the code:

(IBAction) uploadBtn {   
ipc = [[UIImagePickerController alloc] init]; 
ipc.delegate = self;
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[self presentModalViewController:ipc animated:YES];'

Its giving me a warning with the last line, saying:

Method'- presentModalViewController:animated' not found

I am sure that if I used the ViewController class this would work but is there anything I can do/import that will let me do this in just a UIView class?

Again the app builds, but when I try to click the button it crashes

Thanks in advance!

Arpit
  • 6,212
  • 8
  • 38
  • 69
Dan
  • 61
  • 1
  • 3

3 Answers3

1

You're crashing because only UIViewController has that method. You can only present one view controller off of another one.

Jonathan Grynspan
  • 43,286
  • 8
  • 74
  • 104
  • I swear I thought I saw something that suggested a work around to it... Are you positive?? Or am I just going to have to move all this to the ViewController? – Dan Apr 07 '11 at 07:35
  • Yes, I'm positive. Any workaround is going to consist of rebuilding a lot of code to *simulate* the view controller hierarchy. It's not worth fighting the system. – Jonathan Grynspan Apr 07 '11 at 07:39
0

Have a look at get UIView's viewcontroller (iphone). I think you should rethink your design if you need to access view controller from a UIView.

Community
  • 1
  • 1
Krishna
  • 1,871
  • 14
  • 26
0

You could present it from the view's parent view controller:

[[ipc parentViewController] presentModalViewController:yourController animated:yourBool];
Stefan Ticu
  • 2,093
  • 1
  • 12
  • 21