[UIWindow setRootViewController:]报错
2011-10-14 14:07
441 查看
今天想研究iphone的推送通知服务,于是用xcode新建了一个view-base项目,然后再iphone3的真机上运行。
发现报错:
-[UIWindow setRootViewController:]: unrecognized selector sent to instance。查看setRootViewController方法,发现需要4.0以上支持。
解决方案:把出错代码:
self.window.rootViewController = viewController;
替换为:
if( [[[UIDevice currentDevice] systemVersion] compare:@”4.0″ options:NSNumericSearch] == NSOrderedAscending )
[self.window addSubview:self.mainViewController.view];
else self.window.rootViewController = self.mainViewController;
就行了。
这里顺带提一下,ios3.0和ios3.2及以后的视频播放MPMoviewPlayerController也不一样
在ios3.2以前MPMoviewPlayerController的View是不可控制的(大小、位置),而3.2及以后都可以所以在用到MPMoviewPlayerController播放视频的时候如果需要适配3.2以前的
可以这样:
if ([[[UIDevice currentDevice] systemVersion] floatValue]>3.2) {
tempController = [[UIViewController alloc] init];
[tempController.view setBackgroundColor:[UIColor whiteColor]];
UILabel* titleView=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200.0, 40.0)];
[titleView setBackgroundColor:[UIColor clearColor]];
UILabel* curSong = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200.0, 25.0)];
[curSong setTextColor:[UIColor whiteColor]];
[curSong setFont:[UIFont fontWithName:@"Arial Rounded MT Bold" size:16.0]];
[curSong setBackgroundColor:[UIColor clearColor]];
[curSong setText:[NSString stringWithFormat:@"%@",[SongData getInfo:string index:0]]];
[curSong setTextAlignment:UITextAlignmentCenter];
[titleView addSubview:curSong];
[curSong release];
UILabel* curSinger= [[UILabel alloc] initWithFrame:CGRectMake(0.0, 25.0, 200.0, 15.0)];
[curSinger setTextColor:[UIColor grayColor]];
[curSinger setFont:[UIFont fontWithName:@"Arial Rounded MT Bold" size:10.0]];
[curSinger setBackgroundColor:[UIColor clearColor]];
[curSinger setText:[NSString stringWithFormat:@"%@",[SongData getInfo:string index:1]]];
[curSinger setTextAlignment:UITextAlignmentCenter];
[titleView addSubview:curSinger];
[curSinger release];
UIImageView* image=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
image.image=[UIImage imageNamed:@"bg3.jpg"];
[tempController.view addSubview:image];
[image release];
[movie.view setBackgroundColor:[UIColor whiteColor]];
[movie.view setFrame:CGRectMake(0, 320.0, 320.0, 20.0)];
[movie.view setBackgroundColor:[UIColor clearColor]];
[movie setShouldAutoplay:YES];
[movie setControlStyle:MPMovieControlStyleEmbedded];
[tempController.view addSubview:movie.view];
tempController.navigationItem.titleView=titleView;
[movie play];
[self.navigationController pushViewController:tempController animated:TRUE];
}else
[movie play];
发现报错:
-[UIWindow setRootViewController:]: unrecognized selector sent to instance。查看setRootViewController方法,发现需要4.0以上支持。
解决方案:把出错代码:
self.window.rootViewController = viewController;
替换为:
if( [[[UIDevice currentDevice] systemVersion] compare:@”4.0″ options:NSNumericSearch] == NSOrderedAscending )
[self.window addSubview:self.mainViewController.view];
else self.window.rootViewController = self.mainViewController;
就行了。
这里顺带提一下,ios3.0和ios3.2及以后的视频播放MPMoviewPlayerController也不一样
在ios3.2以前MPMoviewPlayerController的View是不可控制的(大小、位置),而3.2及以后都可以所以在用到MPMoviewPlayerController播放视频的时候如果需要适配3.2以前的
可以这样:
if ([[[UIDevice currentDevice] systemVersion] floatValue]>3.2) {
tempController = [[UIViewController alloc] init];
[tempController.view setBackgroundColor:[UIColor whiteColor]];
UILabel* titleView=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200.0, 40.0)];
[titleView setBackgroundColor:[UIColor clearColor]];
UILabel* curSong = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200.0, 25.0)];
[curSong setTextColor:[UIColor whiteColor]];
[curSong setFont:[UIFont fontWithName:@"Arial Rounded MT Bold" size:16.0]];
[curSong setBackgroundColor:[UIColor clearColor]];
[curSong setText:[NSString stringWithFormat:@"%@",[SongData getInfo:string index:0]]];
[curSong setTextAlignment:UITextAlignmentCenter];
[titleView addSubview:curSong];
[curSong release];
UILabel* curSinger= [[UILabel alloc] initWithFrame:CGRectMake(0.0, 25.0, 200.0, 15.0)];
[curSinger setTextColor:[UIColor grayColor]];
[curSinger setFont:[UIFont fontWithName:@"Arial Rounded MT Bold" size:10.0]];
[curSinger setBackgroundColor:[UIColor clearColor]];
[curSinger setText:[NSString stringWithFormat:@"%@",[SongData getInfo:string index:1]]];
[curSinger setTextAlignment:UITextAlignmentCenter];
[titleView addSubview:curSinger];
[curSinger release];
UIImageView* image=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
image.image=[UIImage imageNamed:@"bg3.jpg"];
[tempController.view addSubview:image];
[image release];
[movie.view setBackgroundColor:[UIColor whiteColor]];
[movie.view setFrame:CGRectMake(0, 320.0, 320.0, 20.0)];
[movie.view setBackgroundColor:[UIColor clearColor]];
[movie setShouldAutoplay:YES];
[movie setControlStyle:MPMovieControlStyleEmbedded];
[tempController.view addSubview:movie.view];
tempController.navigationItem.titleView=titleView;
[movie play];
[self.navigationController pushViewController:tempController animated:TRUE];
}else
[movie play];
相关文章推荐
- UIAlertView与[UIApplication sharedApplication].keyWindow.rootViewController的冲突解决
- iOS9 UIWindow rootViewController
- UISplitViewController 只能用在最开始的 window.rootViewController
- UIApplication keyWindow rootViewController 为 nil 的问题
- UI显示系统之 Window 及 HierarchyView,ViewRootImpl,view的绘制等
- 关于self.window.rootViewController的方法调用顺序
- 获取工程中window上面的RootViewController
- self.window.rootViewController都干了些啥事?
- [ios]使用self.view.window.rootViewController presentViewControllert跳转后的返回
- 退出登录功能改变window的rootviewcontroller输入框键盘不会收起
- 由主线程更新UI所想到的Window和RootViewImpl的创建过程
- Xcode改成不用MainWindow.xib 和 RootViewController.xib 的方法
- 获取当前的window 以及设置其rootViewController
- 通过模态弹出视图 self.view.window.rootViewController灵活应用 modalTransitionStyle、modalPresentationStyle
- Xcode改成不用MainWindow.xib 和 RootViewController.xib 的方法
- iphone - self.window.rootViewController vs window addSubview
- Xcode改成不用MainWindow.xib 和 RootViewController.xib 的方法
- 错误显示:2012-03-09 17:20:22.090 viewcontrollerjump[1191:207] *** Assertion failure in -[UIWindowController transition:fromViewController:toViewController
- 关于重新设置window的RootViewController以前的对象没有释放坑
- UI1_ViewController视图切换及Appdelegate