从iOS中的不同线程调用控制器方法

时间:2012-08-19 21:00:09

标签: ios multithreading controller dispatch-async

我正在尝试从另一个线程中运行的音乐渲染函数调用此方法。该方法位于InstrumentGridViewController内。

- (IBAction)stopPlayback:(id)sender{
    [self stopToneUnit];
}

这就是我调用方法的方法:

dispatch_async(dispatch_get_main_queue(), ^{ [InstrumentGridViewController stopPlayback: nil]; } );

但是我收到了这个警告:

Class method `+stopPlayback` not found (return type defaults to `id`)

当我尝试跑步时:

erminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[InstrumentGridViewController stopPlayback:]: unrecognized selector sent to class 0x13e50'

我确定方法已经存在,所以我真的不明白为什么会发生这种情况。

编辑:H2CO3说我应该在当前运行的实例上调用stopPlayback方法。我有什么想法可以做到这一点吗?

1 个答案:

答案 0 :(得分:0)

因为该方法是作为实例方法实现的,而不是作为类方法实现的。您必须在InstrumentGridViewController类的对象上调用它,并且不在类本身上。