【问题标题】:Xcode help? - " 'didRotateFromInterfaceOrientation' undeclared " + " Expected ';' before ':' token "Xcode 帮助? - " 'didRotateFromInterfaceOrientation' 未声明 " + " 预期 ';'在':'标记之前“
【发布时间】:2011-01-21 18:13:44
【问题描述】:

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

这里是“switchviewcontroller.h”文件代码:

#import <UIKit/UIKit.h>

@interface SwitchViewController : UIViewController {

}

-(IBAction)switchview:(id)sender;

@end

这里是“switchviewcontroller.m”文件代码:


#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]];
    }

}

我得到了问题中显示的 2 个错误,所以它不起作用。

【问题讨论】:

  • 代码显示不正确:(
  • 注意:您可以在didRotateFromInterfaceOrientation 的if 子句中使用UIDeviceOrientationIsLandscape(fromInterfaceOrientation) 以使代码更简单。

标签: objective-c cocoa-touch ios ios4


【解决方案1】:

您缺少 -(IBAction)switchview:(id)sender 的实现块 - 将其设为 -(IBAction)switchview:(id)sender {} 并重试。

【讨论】:

  • 现在在 '{' 标记之前显示预期的标识符或 '('。
  • 哦,等一下,我已经让它运行了,但不确定它是否有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-04
相关资源
最近更新 更多