嗨 我收到一个错误,错误消息就像 /IphoneTextFieldViewController.h:13:错误:预期的标识符或'('之前的'{'标记error:expected identifier or'('before'{'token
其实我没有得到为什么会出现这样和我有张贴低于.h文件中的代码和行号13({ - 这个冒号线显示错误),普莱舍帮助我在这一个
谢谢提前
.h文件
#import <UIKit/UIKit.h>
@interface IphoneTextFieldViewController : UIViewController {
IBOutlet UITextField *textField;
IBOutlet UITextField *textField1;
IBOutlet UITextField *textField2;
NSString *String;
}
@property(nonatomic, retain)IBOutlet UITextField *textField;
@property(nonatomic, retain)IBOutlet UITextField *textField1;
@property(nonatomic, retain)IBOutlet UITextField *textField2;
@property(nonatomic, retain)IBOutlet NSString *String;
-(IBAction)changrGreeting;
{ 13: error: expected identifier or '(' before '{' token
self.String=textField.text;
NSString *nameString=String;
self.String=textField1.text;
NSString *nameString1=String;
if ([nameString length]== 0)
{
nameString = @" ";
}
if([nameString1 length]== 0)
{
[email protected]" ";
}
textField2.text=[NSString stringWithFormat:@"%@ %@",textField.text,textField1.text];
}
@end
.m文件
//
// IphoneTextFieldViewController.m
// IphoneTextField
//
// Created by Span on 1/31/11.
// Copyright __MyCompanyName__ 2011. All rights reserved.
//
#import "IphoneTextFieldViewController.h"
#import "IphoneTextFieldAppDelegate.h"
@implementation IphoneTextFieldViewController
@synthesize textField;
@synthesize textField1;
@synthesize textField2;
@synthesize String;
-(IBAction)changrGreeting;
{
self.String=textField.text;
NSString *nameString=String;
self.String=textField1.text;
NSString *nameString1=String;
if([nameString length]==0)
{
[email protected]" ";
}
if([nameString1 length]==0)
{
[email protected]" ";
}
textField2.text=[NSString stringWithFormat:@" %@ %@",textField.text,textField1.text];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[textField resignFirstResponder];
[textField1 resignFirstResponder];
[super touchesBegan:touches withEvent:event];
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[textField release];
[textField1 release];
[textField2 release];
[String release];
[super dealloc];
}
@end
实际上,.m文件中的`;`是无害的。试试看 - 编译器会忽略它。 – 2011-01-31 13:18:21