【问题标题】:NSNotificationCenter postNotificationName crash in swift and object-c, why?NSNotificationCenter postNotificationName 在swift和object-c中崩溃,为什么?
【发布时间】: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


【解决方案1】:

这是我的错,只需将 Selector() 更改为 Selector("doAddEffectsFinished")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-10
    • 2023-02-16
    • 2011-04-08
    • 1970-01-01
    • 2021-04-14
    • 1970-01-01
    • 2011-07-30
    • 2012-04-20
    相关资源
    最近更新 更多