use Autolayout 一个让我纠结的问题,用try-catch解决

问题描述:

在一个页面实例化播放器,并且播放视频文件:

 

[myTabBarController presentMoviePlayerViewControllerAnimated:_moviePlayerController];

当自己重写了一个UIViewController页面,要在这个重写一个播放器。

_myPlayer=[[MyNewPlayerController alloc] initWithNibName:@"MyNewPlayerController" bundle:nil];

        

        [myTabBarController presentViewController:_myPlayer animated:YES completion:^{}]; 

发现,莫名奇妙的报错。
错误让我很纠结:
————————————————————————
handler threw exception
————————————————————————
这个错误,有点头大。
这种错误,最多的可能是数组越界!
可是,没有给出原因,我怎么解决!
不用急,用try-catch
强大的调试利器啊!当得不到错误信息的时候用try-catch

 @try {

        _myPlayer=[[MyNewPlayerController alloc] initWithNibName:@"MyNewPlayerController"bundle:nil];

        

        [myTabBarController presentViewController:_myPlayer animated:YES completion:^{}]; 

 

    }

    @catch (NSException *exception) {

        

        NSLog(@"name----%@",exception.name);

        NSLog(@"reason----%@",exception.reason);

    }

    @finally {

        

    }

 

得到了,相应的输出:

 

name----NSInvalidUnarchiveOperationException

 

reason----Could not instantiate class named NSLayoutConstraint

 
这就好说了嘛。有了线索,顺藤摸瓜!
原来是这样!
在右边的inspector一栏,将interface builder document 下的use auto layout复选框去掉就可以了!
posted @ 2013-03-25 11:15  清风拂月晓  阅读(202)  评论(0)    收藏  举报