开发者

Help with Xcode - Incorrect implementation of class 'secondview' + method definition for '-switchview:' not found

I am trying to create an application in Xcode that will switch to a new view when the phone is rotated from one orientation to another.

Here is the "switchviewcontroller.h" file code:


#import <UIKit/UIKit.h>

@interface SwitchViewController : UIViewController {

}

-(IBAction)switchview:(id)sender;

@end
-----------------------------------------------------------------

And here is the "switchviewcontroller.m" file code:

----------------------------------------
#import "SwitchViewController.h"
#import "secondview.h"

@implementation SwitchViewController

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return YES;
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterface开发者_如何学编程Orientation
{
    if((fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
       (fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight))
    {    
        [[secondview alloc] initWithNibName:@"secondview" bundle:[NSBundle mainBundle]];
    }

}

I get the 2 warnings showed in the question, and it also doesn't work.


well the method definition not found is saying exact that ..... in the code you posted there is no switchview method. The incorrect implementation error message implies that the secondview class doesn't conform to a uiview.


You declared

-(IBAction)switchview:(id)sender;

but you did not implement it.

In your .m file, add

-(IBAction)switchview:(id)sender
{
     //here is the implementation of the switch view method
}

Also, it looks like you're creating an instance of secondview whenever the view is rotated so you will leak one secondview instance each time the interface changes orientation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜