[英]UITextFields aren't allowing me to edit text
我已經在iOS應用中以編程方式創建了兩個UITextField
,並將它們的文本分別設置為_minPrice
和_minPrice
變量。
_minPrice
和_maxPrice
值正確顯示在兩個字段中,但是點擊它們不允許用戶編輯它們,它們只是保留這些靜態值,后退間距不起作用。 關於我的代碼,有什么阻止文本字段被編輯的內容?
// Min Price
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(-25, -76, 70, 30)];
tf.textColor = [UIColor blackColor];
tf.font = [UIFont fontWithName:@"Helvetica-Neue" size:14];
tf.backgroundColor=[UIColor whiteColor];
tf.text= _minPrice;
tf.textAlignment = NSTextAlignmentCenter;
tf.layer.cornerRadius=8.0f;
tf.layer.masksToBounds=YES;
tf.layer.borderColor=[[UIColor lightGrayColor]CGColor];
tf.layer.borderWidth= 1.0f;
// Max Price
UITextField *tf1 = [[UITextField alloc] initWithFrame:CGRectMake(100, -76, 70, 30)];
tf1.textColor = [UIColor blackColor];
tf1.font = [UIFont fontWithName:@"Helvetica-Neue" size:14];
tf1.backgroundColor=[UIColor whiteColor];
tf1.text= _maxPrice;
tf1.textAlignment = NSTextAlignmentCenter;
tf1.layer.cornerRadius=8.0f;
tf1.layer.masksToBounds=YES;
tf1.layer.borderColor=[[UIColor lightGrayColor]CGColor];
tf1.layer.borderWidth= 1.0f;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 400, 400)];
[view addSubview:tf];
[view addSubview:tf1];
[self.view addSubview:view];
嘗試這個! 也許在textField的頂部還有另一個視圖
your_textfield.userInteractionEnabled = YES;
如果這不起作用
添加另一行
[self.view bringSubviewToFront: your_textfield];
您的問題顯然是您要設置的框架...
設置將標簽添加為藍色的視圖的顏色可以揭示您的問題:
如果確保標簽確實在您添加到視圖中(即不是否定的)內,則可以進行編輯。 我所做的只是將tf
的負x和y值更改為正,並且它們是可編輯的:
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(25, 76, 70, 30)];
嘗試在您的文本字段上添加委托方法。 喜歡
- (void) textFieldDidEndEditing:(UITextField *)textField
{
// ADD BREAKPOINT HERE.
}
檢查是否轉到該行代碼。 如果不是這樣,那么可能還有一個觀點。 或者,您可以嘗試將textfield放在前面。
[self.view bringSubviewToFront:yourTextfield];
但這不是解決問題的好例子。 只是為了測試上面是否有視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.