【发布时间】:2019-11-12 12:50:26
【问题描述】:
我试图将值从 swift 类传递到目标 C 类,但出现错误。错误是
“由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[ MainViewController childViewControllerResponseWithAsset:]: 无法识别的选择器发送到实例 0x7f969a133c00"
ChildViewController 快速类:
@objc protocol ChildViewControllerDelegate
{
func childViewControllerResponse(asset:AVAsset)
}
class ChildViewController:UIViewController
{
@objc var delegate: ChildViewControllerDelegate?
@objc var asset:AVAsset!
@objc func apply() {
self.delegate?.childViewControllerResponse(asset: self.Video())
//dismiss view
self.navigationController?.popViewController(animated: false)
}
}
MainViewController 目标 C 类:
#import "Project-Swift.h"
@interface MainViewController()<ChildViewControllerDelegate>
{
-(IBAction)ButtonPressed:(UIButton *)sender{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ChildViewController *vc = (ChildViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ChildViewController"];
AVAsset *asset = self.originalVideoAsset;
vc.asset = asset;
vc.delegate = self;
[self.navigationController pushViewController:vc animated:YES];
}
// Define Delegate Method
-(void)childViewControllerResponse:(AVAsset*)asset
{
self.originalVideoAsset = asset;
}
}
我将如何解决这个问题或者我做错了什么?
【问题讨论】:
-
我建议你依靠 Xcode 的自动完成功能,帮助你找到像这样的导入 API 的精确拼写。
标签: objective-c swift delegates