我在一個視圖控制器上有多個文本字段。我的.m和.h在下面。我是Xcode和Objective-C的新手,如果這只是一個愚蠢的錯誤,請注意。「在'MainUI *'類型的對象上未找到屬性'textField'」
.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
.M:
#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) {
幫助嗎?
我沒有看到中定義的textField屬性您提供的標題代碼。你有「字母」和「numLetters」UITextField屬性,但沒有「textField」屬性。 – Alex
self.textField不匹配您在MainUI.h中定義的任何屬性。你的意思是使用self.letters還是self.numLetters? –
我需要爲每個文本字段執行此操作嗎?對於這個觀點,我只有兩個,但更多的是其他人。 –