2

I'm trying to use a view controller that is only available in Objective-C. I have set up my Bridging-Header, but when I run my method it doesn't include a presentViewController and gives the error No visible @interface for 'AlertSelector' declares the selector 'presentViewController...'

.m

#import "AlertSelector.h"

@implementation AlertSelector : NSObject

- (void) someMethod {
    NSLog(@"SomeMethod Ran");
    UIAlertController * view=   [UIAlertController
                             alertControllerWithTitle:@"My Title"
                             message:@"Select you Choice"
                             preferredStyle:UIAlertControllerStyleActionSheet];

    UIAlertAction* ok = [UIAlertAction
                     actionWithTitle:@"OK"
                     style:UIAlertActionStyleDefault
                     handler:^(UIAlertAction * action)
                     {
                         //Do some thing here
                         [view dismissViewControllerAnimated:YES completion:nil];

                     }];
    UIAlertAction* cancel = [UIAlertAction
                         actionWithTitle:@"Cancel"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             [view dismissViewControllerAnimated:YES completion:nil];

                         }];

[view addAction:ok];
[view addAction:cancel];
[self presentViewController:view animated:YES completion:nil];
}

.h

@interface AlertSelector : NSObject

@property (strong, nonatomic) id someProperty;

- (void) someMethod;

@end

From Swift

var instanceOfCustomObject: AlertSelector = AlertSelector()
    instanceOfCustomObject.someProperty = "Hello World"
    print(instanceOfCustomObject.someProperty)
    instanceOfCustomObject.someMethod()
4

3 回答 3

1

您的AlertSelector类不是UIViewController. 这就是为什么您不能[self presentViewController:view animated:YES completion:nil];AlertSelector.

将视图控制器参数添加到您的someMethod方法并从该参数而不是 self 中显示。

于 2015-07-09T23:53:33.753 回答
0

presentViewController 是 UIViewController 的一个方法。您的 AlertSelector 类不是 UIViewController。

于 2015-07-09T23:54:13.863 回答
0

这与桥接头无关。它是UIViewControllerwhich 实现presentViewController:not NSObject,因此编译器抱怨,因为该方法presentViewController:不存在于NSObject的接口上。

可能的解决方案

要么实现presentViewController:你自己(这是一项艰巨的任务),要么让AlertSelectorUIViewController

。H

@interface AlertSelector : UIViewController

于 2015-07-09T23:57:37.233 回答