I have an Xcode project and would like to switch view from one file, file name is Score (without xib, it’s only Score.h and Score.m) to the main file (it’s name is View and does have a XIB) by using UIbutton in my file Score.m, but I can’t do that ..
Using this code :
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];
}
I get this error : Receiver type 'Score' for instance message doesn't declare a method with selector 'presentModalViewController : animated
Please help .
The error message you are receiving indicates, that Score (the class you are trying to push the new ViewController from) isn’t a ViewController.
Only ViewControllers can present other Viewcontrollers. The Code for the presentation should be (placed in a ViewController):