在头文件中的函数中使用 IBOutlet

发布于 2024-10-20 11:44:20 字数 1214 浏览 0 评论 0原文

您能告诉我如何在存储在头文件中的函数中使用 IBOutlets:

.h 文件:

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>    

@interface MainView : UIView <AVAudioPlayerDelegate>  {

        IBOutlet UILabel *SoundDescriptionLabel;
    IBOutlet UIBarButtonItem *StopSoundButton;

}
- (IBAction)PlayFatGuyWalking:(id)sender;
- (IBAction)PlayRoadRunner:(id)sender;
- (IBAction)ShowInfoPopup:(id)sender;
- (IBAction)PlayChaosRunning:(id)sender;
- (IBAction)PlaySadTrombone:(id)sender;
- (IBAction)PlayBadJokeSound:(id)sender;
- (IBAction)PlayHorrorSynth:(id)sender;
- (IBAction)PlayLKWPeep:(id)sender;
- (IBAction)PlayUiToll:(id)sender;
- (IBAction)StopSound:(id)sender;



AVAudioPlayer *theAudio;



@end


//PlaySound Function
void playSound(NSString *filename,NSString *type){
    [theAudio stop];    
    NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:type];
    theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
//HERE I WOULD LIKE TO DO THIS:
StopSoundButton.enabled=1;
//END OF WHAT I'D LIKE TO DO
        [theAudio play];
    }

帮助我,谢谢

请提前

could you please tell me how i can use IBOutlets in a function stored in the header file:

.h file:

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>    

@interface MainView : UIView <AVAudioPlayerDelegate>  {

        IBOutlet UILabel *SoundDescriptionLabel;
    IBOutlet UIBarButtonItem *StopSoundButton;

}
- (IBAction)PlayFatGuyWalking:(id)sender;
- (IBAction)PlayRoadRunner:(id)sender;
- (IBAction)ShowInfoPopup:(id)sender;
- (IBAction)PlayChaosRunning:(id)sender;
- (IBAction)PlaySadTrombone:(id)sender;
- (IBAction)PlayBadJokeSound:(id)sender;
- (IBAction)PlayHorrorSynth:(id)sender;
- (IBAction)PlayLKWPeep:(id)sender;
- (IBAction)PlayUiToll:(id)sender;
- (IBAction)StopSound:(id)sender;



AVAudioPlayer *theAudio;



@end


//PlaySound Function
void playSound(NSString *filename,NSString *type){
    [theAudio stop];    
    NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:type];
    theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
//HERE I WOULD LIKE TO DO THIS:
StopSoundButton.enabled=1;
//END OF WHAT I'D LIKE TO DO
        [theAudio play];
    }

Please help me

thx in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愛放△進行李 2024-10-27 11:44:20

IBOutlet 对您的代码没有任何影响或效果 - 它是 #define 的!

它用作 Interface Builder 的建议,Interface Builder 可以解析标头,以便它知道该变量可以以某种方式链接到某些图形控件。

An IBOutlet has no impact or effect on your code - it's #defined out!

It is used as a suggestion to Interface Builder, which can parse the header, so that it knows that that variable can become linked to some graphical control in some way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文