【发布时间】:2015-08-04 01:38:00
【问题描述】:
我使用带有 object-c 的 c 库,并快速调用 object-c。这是代码: 1.在HomeViewController.swift中
override func viewWillAppear(animated: Bool) {
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector(), name: "doAddEffectsFinished", object: nil)
}
override func viewWillDisappear(animated: Bool) {
NSNotificationCenter.defaultCenter().removeObserver(self, name: "doAddEffectsFinished", object: nil);
}
在 Fmodwrapper.mm 文件中,
-(void) doAddEffects
{
inpath = [[[NSBundle mainBundle] pathForResource: @"modulator22"
ofType: @"wav"] UTF8String];
[[NSNotificationCenter defaultCenter] postNotificationName:@"doAddEffectsFinished" object:nil];
}
在 HomeViewController.swift 中,我使用如下代码:
func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int){
fmodWrapper.addEffects(0)
}
}
当我运行代码时,它会在 fmodwrapper.mm 的行中崩溃
[[NSNotificationCenter defaultCenter] postNotificationName:@"doAddEffectsFinished" object:nil];
我在 fmodwrapper.mm 中添加了以下代码,但它不起作用
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
请帮助我,我的朋友们,谢谢。
【问题讨论】:
-
如果您发布错误会更容易。为什么你有“Selector()”而不是函数名?
-
您的通知处理程序是什么?在您定义
Selector()的地方,它应该是该对象的实际方法。
标签: ios objective-c swift crash nsnotificationcenter