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