声明选择器presentviewcontroller

Aym*_*ari 2 interface animated ios presentviewcontroller

你好我有点问题.

我有一个项目的应用程序,但它是一个有点旧的应用程序(IOS 7).

我在互联网上看到如何使用好的旧UIAlertView的INSTEAD更新UIAlertController.

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];*/
Run Code Online (Sandbox Code Playgroud)

我收到一个我不明白的错误:

'RFduino'没有可见的@interface声明选择器'presentViewController:animated:completion'

Anb*_*hik 13

而不是使用这个:

[self presentViewController: controller animated: YES completion: nil];
Run Code Online (Sandbox Code Playgroud)

试试这个:

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:^{}];
Run Code Online (Sandbox Code Playgroud)