![](/img/trans.png)
[英]How can I call UITextField delegate methods in a different Objective-C class?
[英]I am using objective-c classes in swift2 , how i can implement delegate methods and bind that delegate
在swift項目中添加Objective-C類時,系統會提示您輸入
“創建橋接頭” ->單擊“創建橋接頭”。 現在,您可以快速使用Objective-C代碼。
有關更多詳細信息, 請參閱
根據您的問題修改解決方案:
//Objective-c class
// Test.h
#import <Foundation/Foundation.h>
@protocol TestDelegate <NSObject>
- (void)testMethod;
@end
@interface Test : NSObject
@property (weak, nonatomic) id<TestDelegate> delegate;
@end
//Test.m
#import "Test.h"
@implementation Test
@synthesize delegate;
- (void)callDelegate
{
[delegate testMethod];
}
@end
//Swift bridging header
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "Test.h"
//Swift class
class ViewController: UIViewController, TestDelegate {
.
.
.
func testMethod() {
print("Delegate");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.