gpt4 book ai didi

ios - 预期的标识符或 '(' xcode 错误来了

转载 作者:行者123 更新时间:2023-11-29 12:01:34 24 4
gpt4 key购买 nike

有两个页面,一个是注册页面,另一个是登录页面。登录页面中的用户名和密码应与注册页面中的数据匹配。为此,我对按钮使用 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";
}

类似的调用方法

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

关于ios - 预期的标识符或 '(' xcode 错误来了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36787308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com