我在禁用UITextField
. 我正在尝试将我的文本字段用作组合框,但是当我使用组合框样式时,我的文本是可编辑的。当我设置userInteractionEnabled = NO
为阻止编辑时,我看不到我的文本字段作为组合框。我可以为这个问题做些什么?
问问题
428 次
5 回答
1
您在文本字段编辑上显示一个操作表。
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if ([textField isEqual:myTextField]){
UIActionSheet *actionsheet = [[UIActionSheet alloc] initWithTitle:@"Please select an option" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Option1", @"Option2", @"Option3", nil];
[actionsheet showInView:self.view];
return NO;
}
return YES;
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
[myTextField setText:[actionSheet buttonTitleAtIndex:buttonIndex]];
}
于 2012-10-09T14:04:20.283 回答
0
用这个:
txtBox.editable = NO;
而不是,
txtBox.userInteractionEnabled = NO;
于 2012-10-09T07:09:27.470 回答
0
使用这个 UITextField 委托:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
设置返回 NO 并打开您的组合框。
于 2012-10-09T07:43:21.653 回答
0
将按钮或其他东西放在 UITextFields 上怎么样。将 Textfields editable 设置为 NO 不是一个好主意,但只会欺骗您的 UI。
于 2012-10-09T07:44:31.883 回答
0
I do not think that using uitextfield as combobox is a good solution.The problem is is you disable the userinteraction or make your textview uneditable how would you catch user taps and activate the list?
If i were you i would refer to a button an a small tableview that pops up whe nyou click the button.It is not easy to implement but a more elegant solution.
于 2012-10-09T07:11:26.100 回答