Reputation: 9472
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()
Upvotes: 2
Views: 383
Reputation: 14780
This has nothing to do with bridging header. It's the UIViewController
which implements presentViewController:
not NSObject
, therefore the compiler complains, because the method presentViewController:
is not present on NSObject
's interface.
Either implement the presentViewController:
yourself (which is a difficult task) or let the AlertSelector
extend from UIViewController
.h
@interface AlertSelector : UIViewController
Upvotes: 0
Reputation: 52548
presentViewController is a method of UIViewController. Your AlertSelector class is not a UIViewController.
Upvotes: 0
Reputation: 9829
Your AlertSelector
class is not a subclass of UIViewController
. This is why you cannot call [self presentViewController:view animated:YES completion:nil];
from an instance of AlertSelector
.
Add a view controller parameter to your someMethod
method and present from that instead of self.
Upvotes: 1