-1

我在一个视图控制器上有多个文本字段。我的 .m 和 .h 在下面。我是 Xcode 和 Objective-C 的新手,所以如果这只是一个愚蠢的错误,请多多指教。

。H:

    #import <UIKit/UIKit.h>

@interface MainUI : UIViewController

@property (weak, nonatomic) IBOutlet UITextField *letters;

@property (weak, nonatomic) IBOutlet UISegmentedControl *par;

@property (weak, nonatomic) IBOutlet UISegmentedControl *basicSym;

@property (weak, nonatomic) IBOutlet UITextField *numLetters;

@property (weak, nonatomic) IBOutlet UIButton *mainBack;

@property (weak, nonatomic) IBOutlet UIButton *mainNext;

@end

米:

#import "MainUI.h"

@interface MainUI ()

@end

@implementation MainUI

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

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

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

- (BOOL)textFieldShouldReturn: (UITextField*)theTextField {
    if (theTextField == self.textField) {
        [theTextField resignFirstResponder];
    }
    return YES;
}
@end

错误出现在(theTextField == self.textField) {请帮忙​​吗?

4

1 回答 1

0

如果您只是想在光标位于文本字段中时用户按 Return 时让键盘消失,这应该足够了:

- (BOOL)textFieldShouldReturn: (UITextField*)theTextField {
    [theTextField resignFirstResponder];
    return YES;
}
于 2013-09-30T19:56:00.567 回答