Iphone 调用另一个UIViewController
我在Iphone 调用另一个UIViewController,iphone,ios,Iphone,Ios,我在UITableView中,用户观看了一段视频。视频播放后,我希望用户进行测试。只是不知道如何调用此视图控制器,以便启动测试 Im在播放列表视图控制器中,想调用TestViewController 导入TestViewController.h。在这个阶段,TestViewController中只包含了UIViewController和我添加到.xib中的一些东西。测试编码尚未完成(这将是下一个问题) 如果有人有时间给我指路,我将不胜感激 -(void) movieFinishedPlaying
UITableView
中,用户观看了一段视频。视频播放后,我希望用户进行测试。只是不知道如何调用此视图控制器,以便启动测试
Im在播放列表视图控制器中,想调用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
在播放视频之前注册MPMoviePlayerPlaybackDidFinishNotification通知(我猜您正在使用MPMoviePlayerController播放视频,对吗?) 当它被触发时,以modally方式向他展示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];
}
presentModalViewController在ios 6中被弃用,所以现在是
ViewController *vc = [[ViewController alloc]init];
[self presentViewController:vc animated:YES completion:NULL];
谢谢,当然还有一段路要走。你是什么意思?如果它不工作,你能粘贴你开始视频的部分代码吗?谢谢@fichek。是的,我正在使用带有通知的MPMoviePlayer。效果真的很好,我有一个提醒告诉我,我已经去了那里。但是,新视图没有显示。我已经完成了所有的设置,我想…在开始播放视频之前插入第一行代码(我不知道您在代码中的什么位置进行设置,所以我不能确切地告诉您在哪里)。第二块代码应该在任何两个方法之间粘贴到ListViewController.m中,并在ListViewController.h中声明为
-(void)playerPlaybackDidFinish:(NSNotification*)通知代码>。如果你不知道在哪里插入什么,粘贴你的.h和.m文件,我会给你看。哦,那个。您将其放在两个背景标记之间:`
- (void)playerPlaybackDidFinish:(NSNotification*)notification
{
TestViewController *testVC = [[TestViewController alloc] init];
[self presentModalViewController:testVC animated:YES];
[testVC release];
[[NSNotification defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:playerViewController];
}
ViewController *vc = [[ViewController alloc]init];
[self presentViewController:vc animated:YES completion:NULL];