ビデオを再生し、その後ビューを情報ページに切り替えるiphoneアプリを作成しようとしています。ユーザーは、情報ページを読んだ後、ビデオが再生される前に元のビューに戻ることができます。最初の切り替えは可能ですが、何らかの理由で2番目の切り替えはできません。AppDelegateでこれを強調するsigabortエラーが発生します。
return UIApplicationMain(argc, argv, nil, NSStringFromClass([videoPlayAppDelegate class]));
これが最初のスイッチの私のコードです...
videoPlayViewController.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import "View2.h"
@interface videoPlayViewController : UIViewController
<MPMediaPickerControllerDelegate, UIAlertViewDelegate>
{
MPMoviePlayerController *moviePlayer;
}
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
-(IBAction) playMovie;
@end
videoPlayViewController.m
#import "videoPlayViewController.h"
@implementation videoPlayViewController
@synthesize moviePlayer;
-(void)playMovie
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"sample" ofType:@"mov"]];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = NO;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
[moviePlayer.view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:@selector(setFullscreen:animated:)])
{
NSLog(@"This method is working");
View2 *second =[[View2 alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
}
//[player.view removeFromSuperview];
}
これが私が元に戻す方法です...
View2.h
#import <UIKit/UIKit.h>
#import "videoPlayViewController.h"
@interface View2 : UIViewController
-(IBAction) goBack;
@end
View2.m
#import "View2.h"
@interface View2 ()
@end
@implementation View2
-(IBAction) goBack
{
//Figure this out
videoPlayViewController *map =[[videoPlayViewController alloc] initWithNibName:@"videoPlayViewController" bundle:nil];
[self presentModalViewController:map animated:YES];
}