在調試程序時,遇到如下兩條信息:
Expected identifier
Expected ';' after method prototype
原因:A.h文件 在B.h文件#import 導致A.h文件報出如上錯誤提示,只要將聲明文件寫在B.m文件中即可解決上述問題。為什么?
B.h 文件
#import <UIKit/UIKit.h> @interface WelcomeViewController : UIViewController @end
B.m文件
#import "WelcomeViewController.h" #import <QuartzCore/QuartzCore.h> #import "IndexViewController.h" #import "InterfaceHelper.h" //要引入的那個.h文件 #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) @interface WelcomeViewController () @end @implementation WelcomeViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self performSelector:@selector(GoToViewController) withObject:nil afterDelay:1]; //1秒后,進入應用程序的主界面 [InterfaceHelper initInterfaceHelper]; NSUserDefaults *configData = [NSUserDefaults standardUserDefaults]; NSLog(@"%@",[configData objectForKey:@"initStart"]); } -(void)GoToViewController { CATransition *animation = [CATransition animation]; animation.delegate = self; animation.duration = 0.7 ; // 動畫持續時間(秒) animation.timingFunction = UIViewAnimationCurveEaseInOut; animation.type = kCATransitionFade;//淡入淡出效果 [[self.view layer]addAnimation:animation forKey:@"animation"]; // MainViewController *myMainViewController = [[MainViewController alloc]initWithNibName:@"MainViewController" bundle:nil]; // [self.view addSubview:myMainViewController.view]; if (iPhone5) { IndexViewController *myIndexViewController = [[IndexViewController alloc]initWithNibName:@"IndexViewController_ip5" bundle:nil]; [self.view addSubview:myIndexViewController.view]; }else{ IndexViewController *myIndexViewController = [[IndexViewController alloc]initWithNibName:@"IndexViewController" bundle:nil]; [self.view addSubview:myIndexViewController.view]; } } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); return NO; } @end