简体   繁体   English

只能以一种方式切换视图,无法切换回,sigabort错误

[英]Can only switch views one way, can't switch back, sigabort error

I'm trying to build an iphone app that plays a video then switches view to an info page after. 我正在尝试构建一个iphone应用程序,该应用程序播放视频,然后再将视图切换到信息页面。 The user can then switch back to the original view before the video plays after reading the info page. 然后,用户可以在阅读信息页面后切换到视频播放之前的原始视图。 I can get the first switch to happen but not the second for some reason. 由于某种原因,我可以进行第一个切换,但不能进行第二个切换。 I get a sigabort error that highlights this in the AppDelegate: 我收到一个sigabort错误,该错误在AppDelegate中突出显示:

    return UIApplicationMain(argc, argv, nil, NSStringFromClass([videoPlayAppDelegate class]));

Here is my code for the first switch... 这是我的第一个开关的代码...

videoPlayViewController.h 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 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];
}

Here's how I switch back... 这是我转回去的方式...

View2.h 查看2.h

#import <UIKit/UIKit.h>
#import "videoPlayViewController.h"

@interface View2 : UIViewController

-(IBAction) goBack;

@end

View2.m 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];


}

That's not "going back", that's going on to a different instance of what you already had. 那不是“回头路”,而是在您已经拥有的东西的另一个实例上。

The inverse of presentModalViewController: is dismissModalViewControllerAnimated: (although, if you check the docs, they're both deprecated) so to get rid of something you've presented as modal, you need to dismiss it. presentModalViewController:的反义是dismissModalViewControllerAnimated:尽管如果检查文档,它们dismissModalViewControllerAnimated:弃用),所以要摆脱以模态形式呈现的内容,则需要将其消除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM