Sending 'void' to parameter of incompatible type 'UIViewController'

714 Views Asked by At

I create a modal UIView with .xib, and when I click to button, I want display this UIView. But I have an error in the presentViewController : Sending 'void' to parameter of incompatible type 'UIViewController'. Thanks for your answers.

- (void)modal {
    modalViewController *mvc = [[modalViewController alloc] initWithNibName:@"modalViewController" bundle:nil];
    UIView * modal = [[UIView alloc] initWithFrame:CGRectMake(self.view.center.x/2, self.view.center.y/2, 240, 320)];
    modal.backgroundColor = [UIColor whiteColor];
    [modal addSubview:mvc.view];
    [self.view addSubview:modal];
}

- (IBAction)showBTN:(id)sender {

    [self presentViewController:[self modal] animated:YES completion:nil];

}
1

There are 1 best solutions below

0
On BEST ANSWER

The presentViewController:animated:completion: first parameter is an instance of UIViewController not void.

What you are trying to do makes not sense, since you are already adding the view from the modalViewController to the current UIViewControllers view. So there is no need to call presentViewController:animated:completion:.

This will add the view to your current view hierarchy:

- (IBAction)showBTN:(id)sender {
    [self modal];
}

Also a small remark, classes should start with a capital letter, so your modalViewController class should actually be named ModalViewController.