gpt4 book ai didi

ios - (iOS)自定义初始化UIViewController时黑屏

转载 作者:行者123 更新时间:2023-11-28 22:35:19 25 4
gpt4 key购买 nike

这是我的第一个问题。我正在尝试制作一个可与 Core Audio 配合使用的应用程序。我找到了这个框架 http://theamazingaudioengine.com/我正在尝试使用,到目前为止,我设法完成了文档中的第一件事,即播放文件。但是,通过在应用程序的委托(delegate)中自定义初始化 UIViewController,我丢失了它的所有内容,并且 View Controller 变成黑色,没有其他元素。

我的 UIViewController 只有一个按钮,我想用它来开始播放文件,但由于我无法访问它,目前,文件会在项目构建时开始播放。

知道我做错了什么吗?

这是我的 appDelegate:

@implementation SoundCheckAppDelegate

@synthesize window = _window;
@synthesize audioController = _audioController;
@synthesize viewController = _viewController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


// Create an instance of the audio controller, set it up and start it running
self.audioController = [[[AEAudioController alloc] initWithAudioDescription:[AEAudioController nonInterleaved16BitStereoAudioDescription] inputEnabled:YES] autorelease];
_audioController.preferredBufferDuration = 0.005;
[_audioController start:NULL];

// Create and display view controller
self.viewController = [[SoundCheckViewController alloc] initWithAudioController:_audioController];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

return YES;
}

@end

还有我的 UIViewController:

@interface SoundCheckViewController ()

@property (nonatomic, strong) AEAudioController *audioController;
@property (nonatomic, strong) AEAudioFilePlayer *loop;

@end

@implementation SoundCheckViewController

- (id)initWithAudioController:(AEAudioController*)audioController {
self.audioController = audioController;

NSError *error;

NSURL *file = [[NSBundle mainBundle] URLForResource:@"Southern Rock Drums" withExtension:@"m4a"];
self.loop = [AEAudioFilePlayer audioFilePlayerWithURL:file
audioController:_audioController
error:&error];
if(error)
NSLog(@"couldn't start loop");

_loop.removeUponFinish = YES;
_loop.loop = YES;
_loop.completionBlock = ^{
self.loop = nil;
};

[_audioController addChannels:[NSArray arrayWithObject:_loop]];

return self;
}



@end

最佳答案

由于您使用的是 Storyboard,因此您应该将所有代码从应用委托(delegate)中取出。 Storyboard会自动实例化您的初始 Controller 并将其显示在屏幕上。通过分配初始化一个,您只是在创建另一个没有任何自定义 View 的。

要添加音频 Controller ,您应该在执行该操作的 SoundCheckViewController 的 viewDidLoad 方法中添加代码,而不是在 init 方法中。这将是执行此操作的常用方法,但我不确定您使用的框架可以实现什么。

关于ios - (iOS)自定义初始化UIViewController时黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16240708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com