我创建了一个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