2013-09-30 58 views
-1

我在一個視圖控制器上有多個文本字段。我的.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) {幫助嗎?

+1

我沒有看到中定義的textField屬性您提供的標題代碼。你有「字母」和「numLetters」UIT​​extField屬性,但沒有「textField」屬性。 – Alex

+2

self.textField不匹配您在MainUI.h中定義的任何屬性。你的意思是使用self.letters還是self.numLetters? –

+0

我需要爲每個文本字段執行此操作嗎?對於這個觀點,我只有兩個,但更多的是其他人。 –

回答

0

如果你只是想使鍵盤消失,當用戶按下回車鍵,而光標在一個文本框,這應該是足夠了:

- (BOOL)textFieldShouldReturn: (UITextField*)theTextField { 
    [theTextField resignFirstResponder]; 
    return YES; 
} 
+0

這將適用於所有文本字段?謝謝! –

+0

是的,只要您將控制器設置爲所有文本字段的代表,它就可以用於所有文本字段。 – Greg

+0

好的,這沒有奏效。它沒有回到報刊上。再有幫助嗎? –

相關問題