NSNotificationCenter postNotificationName在swift和object-c中崩溃,为什么?

时间:2015-08-04 01:38:01

标签: ios objective-c swift crash nsnotificationcenter

我使用带有object-c的c库,并在swift中调用object-c。这是代码:  1.在HomeViewController.swift

 public class RunTimerManager implements Runnable {

public void startTimer() {

}

public void stopTimer() {

}

public void test() {

    new Thread(this).start();

    try {
        wait(10000);
    } catch (Exception e) {
        e.printStackTrace();
    }
    stopTimer();

}

@Override
public void run() {
    // ........
}

在Fmodwrapper.mm文件中,

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);
    }

在HomeViewController.swift中,我使用如下代码:

-(void) doAddEffects
{
    inpath = [[[NSBundle mainBundle] pathForResource: @"modulator22"
                                              ofType: @"wav"] UTF8String];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"doAddEffectsFinished" object:nil];
}

当我运行代码时,它将在fmodwrapper.mm中崩溃,

func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int){
                    fmodWrapper.addEffects(0)   
        }
    }

我在fmodwrapper.mm中添加以下代码,但它不起作用

[[NSNotificationCenter defaultCenter] postNotificationName:@"doAddEffectsFinished" object:nil];

请帮助我,我的朋友,谢谢。

1 个答案:

答案 0 :(得分:0)

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