[英]Xcode 6 if else statements getting an error of "Expected identifier or '('
[英]Expected identifier or '(' xcode error comming
有两个页面,一个用于注册,另一个用于登录。 登录页面中的用户名和密码应与注册页面中的数据一致。 为此,我对按钮使用 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
喜欢
//错误就在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
}
首先你定义
- (IBAction)btnAction:(id)sender
{
//navigation to next page
}
然后调用它
if (x==1)
{
[self btnAction:nil]; //here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.