2

Objective-C でのみ使用できるビュー コントローラーを使用しようとしています。Bridging-Header を設定しましたが、メソッドを実行するpresentViewControllerと a が含まれず、エラーが発生します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

スイフトから

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

メソッドにView Controllerパラメーターを追加し、someMethodselfの代わりにそこから提示します。

于 2015-07-09T23:53:33.753 に答える
0

presentViewController は UIViewController のメソッドです。あなたの AlertSelector クラスは UIViewController ではありません。

于 2015-07-09T23:54:13.863 に答える
0

これは、ブリッジング ヘッダーとは関係ありません。notUIViewControllerを実装するのは です。メソッドがのインターフェイスに存在しないため、コンパイラは不平を言います。presentViewController:NSObjectpresentViewController:NSObject

考えられる解決策

presentViewController:自分で実装する(これは難しい作業です) か、AlertSelectorから拡張させます。UIViewController

.h

@interface AlertSelector : UIViewController

于 2015-07-09T23:57:37.233 に答える