您的位置:首页 > 产品设计 > UI/UE

[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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: