我創建了一個UITextField
編程,(我不使用故事板),並使用此代碼添加它作爲一個subview
到ViewController
:不能使編程方式創建的UITextField編輯(IOS)
@interface ViewController()
@property (nonatomic, strong) UITextField *searchLocationBar;
@end
...
@synthesize searchLocationBar;
...
self.searchLocationBar = [[UITextField alloc] init];
self.searchLocationBar.frame = CGRectMake(0.0f, 0.0f, 320.0f, 40.0f);
self.searchLocationBar.delegate = self;
self.searchLocationBar.borderStyle = UITextBorderStyleRoundedRect;
self.searchLocationBar.placeholder = @"a temporary placeholder";
self.searchLocationBar.userInteractionEnabled = YES;
self.searchLocationBar.clearButtonMode = UITextFieldViewModeAlways;
[self.view addSubview:self.searchLocationBar];
但是,我不能恩特任何文字 - 沒有任何反應,當我點擊textfield
。它不會與其他視圖重疊。
我檢查UITextfield not editable-iphone但沒有效果
我是新手,完全確定,我只是錯過了什麼 - 請指點。 謝謝!
編輯: 一兩件事:我有一個谷歌地圖GMSMapView中分配給self.view爲 self.view = mapView_;如Google API文檔中所寫。 經過一些測試後,我發現使用這個聲明,所有的控件都可以很好地工作,但不是textfields。我不想將地圖視圖移動到任何子視圖,因爲我需要重寫很多東西。
有人可以添加任何建議嗎?
self.searchLocationBar.font = [UIFont fontWithName:@ 「黑體,粗體」 大小:25]。覈實 ? – Rushabh
你是否從'textFieldShouldBeginEditing:'textfield委託方法返回'NO'? – Amar
評論此行self.searchLocationBar.delegate = self; 並檢查它的工作是否 – Rushabh