Reputation: 1
Hi I got one error, the error message is like /IphoneTextFieldViewController.h:13: error: expected identifier or '(' before '{' token
actually am not getting why it shows in this way and i have to post below the code and line number 13 in .h file ({- this colon line shows error), plese help me on this one
Thanks in advance
.h file
#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)
{
nameString1=@" ";
}
textField2.text=[NSString stringWithFormat:@"%@ %@",textField.text,textField1.text];
}
@end
.m file
//
// 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)
{
nameString=@" ";
}
if([nameString1 length]==0)
{
nameString1=@" ";
}
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
Upvotes: 0
Views: 5897
Reputation: 1736
This can also happen happen if you're copy and pasting method names from somewhere else. For instance when im building frameworks whose API's Id like to be congruent with Apples I will often look up the class(es) in question and just copy the "Tasks" section as a starting point. The problem with this is that some sites, like Apples documentation, will display an EN DASH rather than the hyphen that the compiler is expecting.
Upvotes: 0
Reputation: 12787
.h file must be look like
#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;
and in .m
-(IBAction)changrGreeting
{
self.String=textField.text;
NSString *nameString=String;
self.String=textField1.text;
NSString *nameString1=String;
if([nameString length]==0)
{
nameString=@" ";
}
if([nameString1 length]==0)
{
nameString1=@" ";
}
textField2.text=[NSString stringWithFormat:@" %@ %@",textField.text,textField1.text];
}
Upvotes: 5
Reputation: 90117
why do you have implementation in your interface (.h)?
{
self.String=textField.text;
NSString *nameString=String;
self.String=textField1.text;
NSString *nameString1=String;
if ([nameString length]== 0)
{
nameString = @" ";
}
if([nameString1 length]== 0)
{
nameString1=@" ";
}
textField2.text=[NSString stringWithFormat:@"%@ %@",textField.text,textField1.text];
}
this doesn't belong there. Delete it.
and delete the ;
behind -(IBAction)changrGreeting;
in your implementation (.m)
Upvotes: 2
Reputation: 4396
Remove the ; before the {...
it should be
-(IBAction)changrGreeting{
Secondly remove the method definition from the interface... Just keep method declaration...
Cheers
Upvotes: 3