1

我有一个 Xcode 项目,想从一个文件切换视图,文件名是 Score(没有 xib,它只有 Score.h 和 Score.m),通过使用我的文件 Score.m 中的 UIbutton,但我不能这样做..

使用此代码:

UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
btn1.frame = CGRectMake(200, 400, img3.size.width/2, img3.size.height/2);
[btn1 setImage:img3 forState:UIControlStateNormal];
[btn1 setImage:img4 forState:UIControlStateDisabled];
[self addSubview:btn1];

if(btn1.selected) {
    View *second =[[View alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:second animated:YES];
}

我收到此错误: Receiver type 'Score' for instance message doesn't declare a method with selector 'presentModalViewController : animated

请帮忙 。

4

1 回答 1

0

您收到的错误消息表明,Score(您尝试从中推送新 ViewController 的类)不是 ViewController。只有 ViewController 可以呈现其他 Viewcontroller。演示文稿的代码应该是(放置在 ViewController 中):

if(btn1.selected) {
    UIViewController *second =[[UIViewController alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:second animated:YES];
    [second release]
}
于 2012-05-26T21:30:24.867 回答