Objective c Xcode帮助?-&引用';DidRotateFrominterface方向';“未申报”+&引用;预期的'';在';之前:';代币;

Objective c Xcode帮助?-&引用';DidRotateFrominterface方向';“未申报”+&引用;预期的'';在';之前:';代币;,objective-c,cocoa-touch,ios,ios4,Objective C,Cocoa Touch,Ios,Ios4,我试图在Xcode中创建一个应用程序,当手机从一个方向旋转到另一个方向时,它将切换到一个新的视图 以下是“switchviewcontroller.h”文件代码: #import <UIKit/UIKit.h> @interface SwitchViewController : UIViewController { } -(IBAction)switchview:(id)sender; @end 我得到了问题中显示的两个错误,因此它不起作用。您缺少-(iAction)swi

我试图在Xcode中创建一个应用程序,当手机从一个方向旋转到另一个方向时,它将切换到一个新的视图

以下是“switchviewcontroller.h”文件代码:

#import <UIKit/UIKit.h>

@interface SwitchViewController : UIViewController {

}

-(IBAction)switchview:(id)sender;

@end

我得到了问题中显示的两个错误,因此它不起作用。

您缺少
-(iAction)switchview:(id)sender的实现块

-将其设置为
-(iAction)切换视图:(id)发件人{}
,然后重试。

代码显示不正确:(注意:您可以使用
UIDeviceOrientationIsLandscape(来自InterfaceOrientation)
didRotateFromInterfaceOrientation
的if子句中,使代码更简单。它现在在“{”标记之前显示预期的标识符或“(”。哦,等等,现在我已经让它运行了,但不确定它是否有效。
#import "SwitchViewController.h"
#import "secondview.h"

@implementation SwitchViewController

-(IBAction)switchview:(id)sender

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

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    if((fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
       (fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight))
    {    
        [[secondview alloc] initWithNibName:@"secondview" bundle:[NSBundle mainBundle]];
    }

}