[英]Black screen when dismissing a UIViewController with custom transition from within a UINavigationController
[英](iOS) Black screen when custom initializing UIViewController
这是我的第一个问题。 我正在尝试制作一款适用于Core Audio的应用。 我发现这个框架http://theamazingaudioengine.com/我正在尝试使用,到目前为止,我设法在文档中做了第一件事,即播放文件。 但是,通过在app的委托中自定义初始化UIViewController,我丢失了所有内容,视图控制器变黑,没有其他元素。
我的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
由于您正在使用故事板,因此您应该从应用程序委托中获取所有代码。 故事板自动实例化您的初始控制器并将其放在屏幕上。 通过alloc init'ing,你只需要创建另一个没有任何自定义视图。
要添加音频控制器,您应该在SoundCheckViewController的viewDidLoad方法中添加代码,而不是在init方法中。 这是通常的方法,但我不确定你正在使用的框架有什么可能。
我认为你应该首先初始化你的视图控制器。
- (id)initWithAudioController:(AEAudioController*)audioController {
// THIS LINE IS MISSING IN YOUR CODE
self = [super initWithNibName:@"SoundCheckViewController" bundle:nil];
if ( self ) {
self.audioController = audioController;
...
}
return self;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.