gpt4 book ai didi

ios - Swift Bridging-Header Objective-C presentViewController

转载 作者:可可西里 更新时间:2023-11-01 02:20:04 24 4
gpt4 key购买 nike

我正在尝试使用仅在 Objective-C 中可用的 View Controller 。我已经设置了我的 Bridging-Header,但是当我运行我的方法时,它不包含 presentViewController 并给出错误 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

来自 swift

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

最佳答案

您的 AlertSelector 类不是 UIViewController 的子类。这就是为什么您不能从 AlertSelector 的实例调用 [self presentViewController:view animated:YES completion:nil]; 的原因。

将 View Controller 参数添加到您的 someMethod 方法并从中呈现而不是自身。

关于ios - Swift Bridging-Header Objective-C presentViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31330181/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com