我在目标 C++ 类中调用目标 C 方法,在其中创建标签也隐藏状态栏,但状态栏隐藏得很好,而标签没有被创建和显示!如果我在这个目标 C++ 类之外的任何其他地方调用该方法,它可以正常工作,没有任何问题
目标 C++ 类如下
void audioRouteChangeListenerCallback (void *inUserData, AudioSessionPropertyID inPropertyID, UInt32 inPropertyValueSize, const void *inPropertyValue )
{
// ensure that this callback was invoked for a route change
if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return;
{
// Determines the reason for the route change, to ensure that it is not
// because of a category change.
CFDictionaryRef routeChangeDictionary = (CFDictionaryRef)inPropertyValue;
CFNumberRef routeChangeReasonRef = (CFNumberRef)CFDictionaryGetValue (routeChangeDictionary, CFSTR (kAudioSession_AudioRouteChangeKey_Reason) );
SInt32 routeChangeReason;
CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable) {
//Handle Headset Unplugged
NSLog(@"PluggedOut");
}
else if (routeChangeReason == kAudioSessionRouteChangeReason_NewDeviceAvailable)
{
//Handle Headset plugged in
NSLog(@"Something Plugged In");
audiotest *test = [[audiotest alloc] init];
ArmorController *armorcontroller =[[ArmorController alloc]init];
NSLog(@"%d", [test Checkheadphonestatus]);
if([test Checkheadphonestatus] == 1)
{
[armorcontroller deviceconnectedalert];
}
else if([test Checkheadphonestatus] == 0)
{
NSLog(@"Device not connected");
}
}
}
在目标 C++ 类中未正确执行的目标 C 方法如下
- (void) deviceconnectedalert
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 320, 30)];
[self.titleLabel setText:@"Device Connected Successfully!"];
self.titleLabel.backgroundColor =[UIColor redColor];
[self.view addSubview:self.titleLabel];
}