2011-12-16 53 views

回答

7

您可以創建一個隱藏的UITextField,並將其設置爲firstResponder。在輸入任何字符時,將隱藏的UITextField中的字符複製到UILabel。

0

爲什麼不只是用適當樣式的(可見的)UITextField替換標籤?然後在用戶再次點擊按鈕(或某個地方的「完成」按鈕)時將其交換。

0

這是一種與你想要的相反的東西,但是這個你可以把代碼弄亂並讓它在buttonpress上可見。同樣在此示例中,當用戶觸摸背景時觸發更改。你可以將它設置爲你想要的任何按鈕而不是背景。

隱藏鍵盤當用戶點擊背景

#import <UIKit/UIKit.h> 

@interface hideKeyboardViewController : UIViewController { 
     UITextField *textField; 
} 
@property (nonatomic, retain) IBOutlet UITextField *textField; 
- (IBAction)textFieldReturn:(id)sender; 
- (IBAction)backgroundTouched:(id)sender; 
@end 

選擇hideKeyboardViewController.m文件,並通過調用我們的TextField對象的resignFirstResponder方法實施行動:

#import "hideKeyboardViewController.h" 
@implementation hideKeyboardViewController 
@synthesize textField; 
-(IBAction)textFieldReturn:(id)sender 
{ 
     [sender resignFirstResponder]; 
} 
-(IBAction)backgroundTouched:(id)sender 
{ 
     [textField resignFirstResponder]; 
} 
. 
. 
@end 

More on this subject here

相關問題