iOS - 崩溃自定义视图

时间:2011-08-09 01:39:46

标签: objective-c ios uiviewcontroller custom-view

项目因此错误而崩溃。

2011-08-08 19:34:27.539 MCIT[12233:207] -[TrailersViewController initWithFrame:]: unrecognized selector sent to instance 0x58396e0
2011-08-08 19:34:27.542 MCIT[12233:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TrailersViewController initWithFrame:]: unrecognized selector sent to instance 0x58396e0'

在代理

上的此方法中
-(void)switchToTrailerOne
{   
    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    CGRect screenBounds = CGRectMake(0, 0, screenSize.width, screenSize.height);
    TrailersViewController *trailersController = [[TrailersViewController alloc] initWithFrame:screenBounds];

    [self.navController pushViewController:trailersController animated:NO];
    [trailersController goToFirstTrailer];
}

欢迎提出问题,但如果您希望查看代码,那么违规的视图控制器文件就在这里。

http://mytheral.com/TrailersViewControllerH.html
http://mytheral.com/TrailersViewControllerM.html

1 个答案:

答案 0 :(得分:2)

您正在尝试在UIViewController上使用initWithFrame。您将在UIView子类上使用initWithFrame。您获得的错误是正确的,因为UIViewController不会响应该消息,因为它没有initWithFrame选择器。您可以在UIViewController中设置UIViewController的视图属性框。