我有一个Xcode项目,并希望从一个文件切换视图,文件名是Score(没有xib,它只有Score.h和Score.m)到主文件(它的名称是View并且确实有XIB)在我的文件Score.m使用的UIButton,但我不能这样做..通过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
请帮助。
你的分数是多少?你能告诉我们score.h吗? –
什么是包含按钮的视图控制器?您可以从该视图控制器调用presentModalViewController。 – nhahtdh
你说过View有一个XIB,所以你应该在initWithNibName中使用它。 'View * second = [[View alloc] initWithNibName:@“View.xib”bundle:nil];'。 – lnafziger