简体   繁体   中英

Expected identifier or '(' xcode error comming

There are two pages one for registration and other for login. username and password in login page should match with data in registration page. To do this i am using if-else statement for button that if data in registration page== login page username and password then go to next page on button click otherwise display error.

This is .h file

#import <UIKit/UIKit.h>

@interface ViewController2 : UIViewController<UITextFieldDelegate>

@property(strong,nonatomic)NSString *dataString;

@property (strong, nonatomic) IBOutlet UITextField *inputTxt1;

@property (strong, nonatomic) IBOutlet UITextField *inputTxt2;

@property (strong, nonatomic) IBOutlet UILabel *lblOutput;

- (IBAction)btnAction:(id)sender;

@end

this is .m file

#import "ViewController2.h"

@interface ViewController2 ()
{
    int x;
}
@end

@implementation ViewController2

- (void)viewDidLoad {

    [super viewDidLoad];

    self.navigationItem.title=@"Login Id Page";

    NSLog(@"Data String is %@",self.dataString);

    _inputTxt1.delegate=self;

    _inputTxt2.delegate=self;

    _inputTxt1.returnKeyType=UIReturnKeyNext;

    _inputTxt2.returnKeyType=UIReturnKeyDone;

    if (_inputTxt1.text == self.dataString){
        x=1;
    }
    else{
        x=0;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == self.inputTxt1) {

        [self.inputTxt2 becomeFirstResponder];
    }
    else if (textField == self.inputTxt2)
    {
        [textField resignFirstResponder];
    }
    return YES;
}

//error is comming right here at if statement:-

if (x==1)
{
    - (IBAction)btnAction:(id)sender {
        //navigation to next page
    }
}

else
{
    _lblOutput.text = @"wrong username or password";
}
@end

do like

//error is comming right here at if statement:-

if (x==1)
{
   [self performseguewithIdentifier:@"xxxx"];
}

else
{
_lblOutput.text = @"wrong username or password";
  }

choice-2

if (x==1)
{
  [self btnAction:nil];
}

else
{
_lblOutput.text = @"wrong username or password";
  }

cal method like

- (IBAction)btnAction:(id)sender {
    //navigation to next page
   [self performseguewithIdentifier:@"xxxx"];
  // or do ur stuff here
}

first you define

    - (IBAction)btnAction:(id)sender 
    {
     //navigation to next page
    }

then call it

if (x==1)
{
    [self btnAction:nil];   //here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM