0

Im just learning following beginner tutorial book , i have this code :

- (void) presentImagePickerUsingCamera:(BOOL)useCamera
{
    UIImagePickerController *cameraUI = [UIImagePickerController new];
    cameraUI.sourceType = (useCamera? UIImagePickerControllerSourceTypeCamera:
                                      UIImagePickerControllerSourceTypePhotoLibrary);

    cameraUI.mediaTypes = @[(NSString*)kUTTypeImage];
    cameraUI.delegate = self;
    [[self presentingViewController] dismissViewControllerAnimated:YES completion:nil]; 
    [self presentingViewController:cameraUI];
}

and this is the interface :

#import <UIKit/UIKit.h>
#import "MyWhatsit.h"

    @interface MSDetailViewController : UIViewController <UISplitViewControllerDelegate,
                                                           UIActionSheetDelegate,
                                                           UIImagePickerControllerDelegate,
                                                           UINavigationControllerDelegate>


    @property (strong,nonatomic) MyWhatsit* detailItem;
    @property (weak,nonatomic) IBOutlet UITextField *nameField;
    @property (weak,nonatomic) IBOutlet UITextField *locationField;
    @property (weak,nonatomic) IBOutlet UIImageView *imageView;
    - (IBAction)changeDetail:(id)sender;
    - (IBAction)chooseImage:(id)sender;
    - (void) presentImagePickerUsingCamera:(BOOL)useCamera;
    @end

gives me the error:

code/MSDetailViewController.m:89:11: No visible @interface for 'MSDetailViewController' declares the selector 'presentingViewController:'

i did try to find answers like here

but nothing help , what I'm doing wrong here ?

Community
  • 1
  • 1
user63898
  • 29,839
  • 85
  • 272
  • 514

2 Answers2

1

That is because of the line:

[self presentingViewController:cameraUI];

There is no such method. You are trying to set the controller that presented your view controller. It has no setter since it is readonly (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/presentingViewController)

And if you wanted to set its value, @property gives you this (with set before the variable's name) [self setSomeInstanceVariable: @"Something"]; as a setter. So, for example:

@property(nonatomic, strong)NSString *foo;

gives you

[self foo]; //getter
[self setFoo:@"bar"]; // setter

If you want to present a view controller, then you should use the method:

presentViewControllerAnimated:completion
Afonso Tsukamoto
  • 1,184
  • 1
  • 12
  • 21
0

To present something the method is:

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion

So in your case:

[self presentViewController:cameraUI animated:YES completion:nil];
Dima
  • 23,484
  • 6
  • 56
  • 83