我正在使用react-native-autocomplete-input,我想禁用 //Textfields
@IBOutlet weak var text1: UITextField!
@IBOutlet weak var text2: UITextField!
@IBOutlet weak var text3: UITextField!
@IBOutlet weak var text4: UITextField!
@IBOutlet weak var text5: UITextField!
@IBOutlet weak var text6: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//Delegates each textfield
text1.delegate = self
text2.delegate = self
text3.delegate = self
text4.delegate = self
text5.delegate = self
text6.delegate = self
//Tags each textfield
text1.tag = 1
text2.tag = 2
text3.tag = 3
text4.tag = 4
text5.tag = 5
text6.tag = 6
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
let nextTag: NSInteger = textField.tag + 1;
if let nextResponder: UIResponder! = textField.superview!.viewWithTag(nextTag){
nextResponder.becomeFirstResponder()
}
else {
textField.resignFirstResponder()
}
return false
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let destination = segue.destinationViewController as! secondView
if segue.identifier == segueID {
//Adds the textfield entries to the string array on the second view controller
destination.stringArray = view.subviews.flatMap { ($0 as? UITextField)?.text }
destination.delegate = self
}
}
输入。我尝试添加'output-xml' => true
(在数据加载时禁用它...现在用户可以在自动填充功能可用之前开始输入。)
我确信有办法这样做,但我无法弄明白。代码如下:
<Autocomplete />
答案 0 :(得分:2)
react-native-autocomplete-input本身不提供禁用输入字段的功能。因此,传递disabled = {this.state.loading}将无效。
您可以通过进入node_modules/react-native-autocomplete-input
文件夹并修改index.js
文件来编辑该包。
将index.js中的render函数更改为以下内容。现在它接受isEditable prop并将其传递给TextInput
render() {
const { showResults } = this.state;
const { containerStyle, inputContainerStyle, onEndEditing, isEditable, style, ...props } = this.props;
return (
<View style={[styles.container, containerStyle]}>
<View style={[styles.inputContainer, inputContainerStyle]}>
<TextInput
editable={isEditable}
style={[styles.input, style]}
ref="textInput"
onEndEditing={e =>
this._showResults(false) || (onEndEditing && onEndEditing(e))
}
{...props}
/>
</View>
{showResults && this._renderItems()}
</View>
);
}
现在,您可以将isEditable={this.loading}
作为道具传递给<Autocomplete />