Xcode 中的预期标识符?我需要帮助!
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5752434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Expected Identifiers in Xcode? I need need help!
提问by konradsjohn
im using 3.2.6 iOS 4.3 to begins with. now the question i have is its telling me I have an (located on the "(@Implementation window, hvController;"):
我使用 3.2.6 iOS 4.3 开始。现在我的问题是它告诉我我有一个(位于“(@Implementation window, hvController;”):
Expected Identifier or '(' before '@' token
'@' 标记前的预期标识符或 '('
in the Delegate.m class
在 Delegate.m 类中
//HelloUniverseAppDelegate.M
(@Implementation window, hvController;
(...
//HelloUniverseAppDelegate.m
- (void)applicationDidFinishishLaunching:(UIApplication *)application {
HelloUniverseController *hvc = [[HelloUniverseController alloc]
inWihhNibName:@"HelloUniverse" bundle:[NSBundle mainBundle]];
self.hvController = hvc;
[hvc release];
[window addSubview:[self.hvController view]];
// Override point for customization after application launch
[window makeKeyAndVisible ;
}
- (Void)dealloc {
[hvController release];
[window release];
[super dealloc];
}
HelloUniverseController *hvc = [HelloUniverseController alloc];
hvc = [hvc initWithNibName:@"HelloUniverse" bundle:[NSBundle mainBundle]];
#import "HelloUniverseAppDelegate.h"
@implementation HelloUniverseAppDelegate
@synthesize window;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
*/
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
/*
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
*/
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}
- (void)applicationWillTerminate:(UIApplication *)application {
/*
Called when the application is about to terminate.
See also applicationDidEnterBackground:.
*/
}
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
*/
}
- (void)dealloc {
[window release];
[super dealloc];
}
@end
now also its telling me I have a similar error in the Controller.h with
Expected Identifier before '{' token
its located on the "- (void)dealloc :{" line. the code I have for it is
#import <UIKit/UIKit.h>
@interface HelloUniverseController : UIViewController {
IBOutlet UITextField *txtFirstName;
IBOutlet UITextField *txtLastName;
IBOutlet UILabel *lblMessage;
}
- (IBAction) btnClickMe_Clicked:(id)sender;
//HelloUniverseController.m
- (void)dealloc :{
[txtFirstName release];
[txtLastName release];
[lblMessage release];
[super dealloc];
}
@end
im also very new at this, my second day ever using a mactonish as well as first with Xcode.
我在这方面也很新,我使用 mactonish 的第二天以及第一次使用 Xcode。
回答by Caleb
Objective-C requires that classes have two parts: the interface, which usually appears in a .h file and declares the class' instance variables, properties, and methods; and the implementation, which should be in a .m file and defines the class' methods. You seem to be trying to define the -dealloc
method inside an @interface block rather than inside an @implementation block, and that's leading to at least one of the errors you're getting.
Objective-C 要求类有两部分:接口,通常出现在 .h 文件中,声明类的实例变量、属性和方法;和实现,它应该在一个 .m 文件中并定义类的方法。您似乎试图-dealloc
在 @interface 块内而不是在 @implementation 块内定义方法,这至少会导致您遇到的错误之一。
Frankly, one cannot avoid the impression that you've copied and pasted code from somewhere without understanding very much about the language. There are a number of blatant errors that just don't make any sense, including the one I just described and the #import statement that seems to be part of your -applicationDidFinishLaunching
method.
坦率地说,人们无法避免一种印象,即您从某处复制并粘贴了代码,但对语言的了解并不多。有许多明显的错误没有任何意义,包括我刚刚描述的错误和似乎是您-applicationDidFinishLaunching
方法的一部分的#import 语句。
StackOverflow is a great community that will, I'm sure, be happy to help you as you learn to program. However, you'll quickly wear out your welcome if you haven't made an effort to learn the basic syntax of the language. More importantly, it's really not going to help you if we just keep correcting your errors. Please, please read Learning Objective-C: A Primer. Or, if you don't have any experience with C-based languages (C, C++, C#, Java...) and some form of object-oriented programming, consider picking up a third-party book aimed at beginners. Thanks to the huge popularity of iPhone and iPad, there are plenty of books to choose from.
StackOverflow 是一个很棒的社区,我敢肯定,它很乐意在您学习编程时为您提供帮助。但是,如果您还没有努力学习该语言的基本语法,您很快就会受到欢迎。更重要的是,如果我们只是不断地纠正你的错误,它真的不会帮助你。请阅读学习目标-C:入门。或者,如果您对基于 C 的语言(C、C++、C#、Java...)和某种形式的面向对象编程没有任何经验,请考虑选择面向初学者的第三方书籍。由于 iPhone 和 iPad 的大受欢迎,有大量书籍可供选择。
回答by saadnib
Remove this
删除这个
(
before
前
(@implementation