2011-08-07 85 views
0

我在UITableView並且用戶已觀看視頻。在視頻後,我希望用戶參加測試。只是不知道如何調用這個視圖控制器,所以我可以開始測試。調用另一個UIViewController

Im在PlayListViewController並且想撥打TestViewController

TestViewController.h已導入。在這個階段,所有TestViewController中都有UIViewController和我在.xib中添加的一些內容。測試編碼尚未完成(這將是下一個問題)。

如果有人有時間給我指示,我將不勝感激。

-(void) movieFinishedPlaying: (NSNotification *) note { 
    [[NSNotificationCenter defaultCenter] 
    removeObserver:self 
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:[player moviePlayer]]; 



    [player release]; 
    NSLog(@"Video has finished playing\n"); 

    // To the test 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info" 
                message:@"Now for the test!" 
                delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles: nil]; 
    [alert show]; 
    [alert release]; 

    // Call on test here 
    TestViewController *testVC = [[TestViewController alloc] init]; 
    [self presentModalViewController:testVC animated:YES]; 
    [testVC release]; 


} 

我有這樣的TestViewController.h

#import <UIKit/UIKit.h> 


@interface TestViewController : UIViewController { 

    UIWindow *tVC; 
    UIViewController *testVC; 

} 

@property (nonatomic, retain) IBOutlet UIWindow *tVC; 
@property (nonatomic, retain) IBOutlet UIViewController *testVC; 

@end 

這在M檔

#import "TestViewController.h" 

@implementation TestViewController 
@synthesize testVC, tVC; 

回答

2

註冊MPMoviePlayerPlaybackDidFinishNotification通知播放視頻之前(我猜你正在使用的MPMoviePlayerController到播放視頻吧?):

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerViewController]; 

,當它獲得的發射,模態展示他TestViewController的實例,並註銷通知:

- (void)playerPlaybackDidFinish:(NSNotification*)notification 
{ 
    TestViewController *testVC = [[TestViewController alloc] init]; 
    [self presentModalViewController:testVC animated:YES]; 
    [testVC release]; 
    [[NSNotification defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:playerViewController]; 
} 
+0

謝謝,在路上肯定會進一步。 – Jorgen

+0

你是什麼意思?如果它不起作用,你可以粘貼代碼的一部分來開始視頻嗎? –

+0

謝謝@fichek。是的,我正在使用帶有通知的MPMoviePlayer。工作真的很好,我有一個警示,告訴我我已經去了那裏。但是新視圖並未顯示出來。我已經完成了所有的設置,我認爲... – Jorgen

0

presentModalViewController的ios 6已被棄用所以現在

ViewController *vc = [[ViewController alloc]init]; 
    [self presentViewController:vc animated:YES completion:NULL]; 
相關問題