1
我试图通过UILabel
与AudioServicesAddSystemSoundCompletion
但我无法操纵completionCallback
方法内的值。我使用ARC和Xcode建议添加(_bridge void*)
。传递参数与AudioServicesAddSystemSoundCompletion
任何帮助将不胜感激。
-(void) playWordSound:(UILabel *)label
{
NSString *path;
SystemSoundID soundId;
switch (label.tag)
{
case 1:
..........
break;
}
NSURL *url = [NSURL fileURLWithPath:path];
AudioServicesCreateSystemSoundID((CFURLRef)objc_unretainedPointer(url), &soundId);
AudioServicesPlaySystemSound(soundId);
AudioServicesAddSystemSoundCompletion (soundId, NULL, NULL,
completionCallback,
(__bridge void*) label);
}
static void completionCallback (SystemSoundID mySSID, void* data) {
NSLog(@"completion Callback");
AudioServicesRemoveSystemSoundCompletion (mySSID);
//the below line is not working
//label.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
}
非常感谢,它现在正在为我工作。你能简单地解释一下noob背后的想法,以及它究竟做了什么? – garethdn
它是在ARC中引入的,用于在存储到泛型类型(如void *)时处理重计数。请参阅[ARC和桥接转换](http://stackoverflow.com/questions/7036350/arc-and-bridged-cast) – Joe
乔,你能告诉我如何从'completionCallback'方法中调用另一个方法。在我更改文字颜色后,我尝试用'[self anotherMethod]'调用另一个方法,但它不适用于我。 – garethdn