我正在尝试构建一个播放视频的iphone应用,然后将视图切换到信息页面。然后,用户可以在阅读信息页面之后切换回视频播放前的原始视图。我可以让第一个开关发生但不是第二个出于某种原因。我得到一个sigabort错误,在AppDelegate中强调了这一点:
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];
}
答案 0 :(得分:1)
那不是“回头”,而是在你已经拥有的不同实例上。
presentModalViewController:
的倒数是dismissModalViewControllerAnimated:
(但是,如果你检查文档,它们都被弃用了)所以为了摆脱你作为模态呈现的东西,你需要忽略它