declares the selector presentviewcontroller

白昼怎懂夜的黑 提交于 2019-12-06 11:18:32

问题


Hello I have a little problem.

I got an application for a project, but it is a somewhat old application (IOS 7).

I saw on the internet how to update the UIAlertController Using INSTEAD of good-old UIAlertView.

if (error.code) {
cancelBlock = block;


UIAlertController *alert = [UIAlertController alertControllerWithTitle: @"Message"
                                                                    message: @"Peripheral Disconnected with Error"
                                                             preferredStyle: UIAlertControllerStyleAlert];

UIAlertAction *alertAction = [UIAlertAction actionWithTitle: @"OK"
                                                      style: UIAlertActionStyleDestructive
                                                    handler: ^(UIAlertAction *action) {
                                                        NSLog(@"OK");
                                                    }];

[alert addAction: alertAction];

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







/*  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Peripheral Disconnected with Error"
                                                    message:error.description
                                                   delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];*/

I get an error that I do not understand:

No visible @interface for 'RFduino' declared the selector 'presentViewController: animated: completion'


回答1:


Instead of using this:

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

Try this:

UIViewController *viewController = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
if ( viewController.presentedViewController && !viewController.presentedViewController.isBeingDismissed ) {
    viewController = viewController.presentedViewController;
}

NSLayoutConstraint *constraint = [NSLayoutConstraint 
    constraintWithItem:alert.view 
    attribute:NSLayoutAttributeHeight 
    relatedBy:NSLayoutRelationLessThanOrEqual 
    toItem:nil 
    attribute:NSLayoutAttributeNotAnAttribute 
    multiplier:1 
    constant:viewController.view.frame.size.height*2.0f];

[alert.view addConstraint:constraint];
[viewController presentViewController:alert animated:YES completion:^{}];



回答2:


presentViewController: animated: completion: is a method of UIViewController. The class where you have made a call to this method, is that a subclass of UIViewController?



来源:https://stackoverflow.com/questions/35794964/declares-the-selector-presentviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!