Xcode 中的预期标识符?我需要帮助!
我首先使用 3.2.6 iOS 4.3。现在我的问题是它告诉我我有一个(位于“(@Implementation窗口,hvController;”):
'@'标记之前的预期标识符或'('
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
我对此也很新,这是我使用 mactonish 的第二天,也是我使用 Xcode 的第一天。
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;"):
Expected Identifier or '(' before '@' token
in the Delegate.m class
//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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Objective-C 要求类有两部分:接口,通常出现在 .h 文件中,声明类的实例变量、属性和方法;以及实现,它应该位于 .m 文件中并定义类的方法。您似乎试图在 @interface 块内而不是在 @implementation 块内定义
-dealloc
方法,这至少会导致您遇到的错误之一。坦率地说,人们无法避免这样一种印象:您从某个地方复制并粘贴了代码,但对这种语言并没有非常了解。有许多明显的错误没有任何意义,包括我刚刚描述的错误和似乎是
-applicationDidFinishLaunching
方法一部分的 #import 语句。StackOverflow 是一个很棒的社区,我确信它会很乐意在您学习编程时为您提供帮助。然而,如果您没有努力学习该语言的基本语法,那么您很快就会感到不受欢迎。更重要的是,如果我们只是不断纠正你的错误,那对你真的没有帮助。请阅读学习 Objective-C:入门< /a>.或者,如果您没有任何基于 C 的语言(C、C++、C#、Java...)和某种形式的面向对象编程的经验,请考虑选择一本针对初学者的第三方书籍。由于 iPhone 和 iPad 的广泛普及,有大量的书籍可供选择。
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.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.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.
删除这个
之前
Remove this
before