预期的标识符或'('xcode错误即将发生

时间:2016-04-22 07:13:01

标签: ios objective-c iphone xcode

有两个页面用于注册,另一个用于登录。登录页面中的用户名和密码应与注册页面中的数据匹配。要做到这一点,我使用if-else语句为按钮,如果注册页面中的数据==登录页面用户名和密码然后转到下一页按钮单击否则显示错误。

这是.h文件

#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

这是.m文件

#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

2 个答案:

答案 0 :(得分:1)

喜欢

//错误正在if语句中出现: -

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

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

<强>选择-2

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

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

cal方法如

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

答案 1 :(得分:0)

首先定义

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

然后调用它

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