簡體   English   中英

預期的標識符或 '(' xcode 錯誤即將到來

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM