1

我遇到了“使用未声明的标识符”错误。似乎这可能有很多原因,我看不出我的问题是什么。首先,这是代码:

#import "CMViewController.h"
#import "CMAEncode.h"

@interface CMViewController ()
@property (weak, nonatomic) IBOutlet UITextView *toCode;
@property (weak, nonatomic) IBOutlet UITextView *Coded;
@property (weak, nonatomic) IBOutlet UISwitch *onOrOff;

- (IBAction)StartEncodeDecode:(id)sender;




@end


@implementation CMViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)StartEncodeDecode:(id)sender {

    NSString *finishedText;
    NSString *toCode = self.toCode.text;
    if (self.onOrOff.on == TRUE) {
        finishedText = [CMAEncode encodeText:toCode];
        self.Coded.text = finishedText;
    } else {
    }

    -(BOOL)textFieldShouldReturn:(UITextField *)textField // Undeclared Identifier here.
    {
        [textField resignFirstResponder];
        return YES;
    }

}
@end

我正在尝试让文本字段辞职第一响应者,以便键盘返回。但我真的只想知道为什么会发生这个错误,它可能会帮助人们解决这个错误的未来实例。

4

1 回答 1

2

您在另一个方法中定义了一个方法,这在任何语言Objective-c中都是不允许的。请textFieldShouldReturn:按照StartEncodeDecode:以下方法移动

- (IBAction)StartEncodeDecode:(id)sender {
    NSString *finishedText;
    NSString *toCode = self.toCode.text;
    if (self.onOrOff.on == TRUE) {
        finishedText = [CMAEncode encodeText:toCode];
        self.Coded.text = finishedText;
    } else {
    }
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
于 2013-08-27T03:55:59.327 回答