2012-08-03 75 views
0

我試圖構建一個iphone應用程序,播放視頻,然後切換到信息頁面後的視圖。在閱讀信息頁面之後,用戶可以在視頻播放之前切換回原始視圖。出於某種原因,我可以得到第一個開關,但不是第二個開關。我得到一個錯誤SIGABORT,突出這在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]; 


} 

回答

1

那不是 「回去」,這是怎麼回事,以你已經有什麼不同的實例。

presentModalViewController:的倒數是dismissModalViewControllerAnimated:(儘管如果您檢查文檔,它們都會被棄用),所以爲了擺脫您以模態形式呈現的內容,您需要解除它。

+0

太棒了!非常感謝@Phillip Mills!我試過新版本[self dismissViewControllerAnimated:YES completion:nil],它的工作原理! – skinnypinny 2012-08-03 11:48:32