user63898
user63898

Reputation: 30915

iOS presentingViewController gives No visible @interface error

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 ?

Upvotes: 0

Views: 431

Answers (2)

Dima
Dima

Reputation: 23634

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];

Upvotes: 0

Afonso Tsukamoto
Afonso Tsukamoto

Reputation: 1214

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

Upvotes: 1

Related Questions