React native 本机iOS中的文本输入
我在react native中有一个TextInput组件React native 本机iOS中的文本输入,react-native,textinput,React Native,Textinput,我在react native中有一个TextInput组件 <TextInput style={styles.searchBar} value={this.state.searchText} onChange={this.setSearchText.bind(this)} placeholder='Search State' /> 这在android中运行得非常好,
<TextInput
style={styles.searchBar}
value={this.state.searchText}
onChange={this.setSearchText.bind(this)}
placeholder='Search State'
/>
这在android中运行得非常好,但在iOS应用程序中并没有显示Textbox。而且,没有什么可以找到问题所在
有人能帮忙解决这个问题吗?您应该给出textinput的高度和宽度,以便将textinput显示为:
<Textinput style={{height:200, width:300}}/>
下面是一个代码示例,演示了在iOS上为
TextInput
组件提供高度的必要性。中没有明确说明,但仔细查看,您会注意到代码示例的iOS部分提供了一个高度,而android示例没有。下面是一个完整的代码示例,它在视图的中心显示一个TextInput
:
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
TextInput,
View
} from 'react-native';
class MyApp extends Component {
constructor (props) {
super(props);
this.state = {
searchText: ''
};
}
setSearchText (e) {
this.setState({
searchText: e.target.value
});
}
render () {
return (
<View style={styles.container}>
<TextInput
style={styles.searchBar}
value={this.state.searchText}
onChange={this.setSearchText.bind(this)}
placeholder='Search State'
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
searchBar: {
borderWidth: 1,
height: 40
}
});
AppRegistry.registerComponent('MyApp', () => MyApp);
import React,{Component}来自'React';
进口{
评估学,
样式表,
文本输入,
看法
}从“反应本机”;
类MyApp扩展组件{
建造师(道具){
超级(道具);
此.state={
搜索文本:“”
};
}
设置搜索文本(e){
这是我的国家({
搜索文本:e.target.value
});
}
渲染(){
返回(
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
为内容辩护:“中心”,
对齐项目:“中心”
},
搜索栏:{
边框宽度:1,
身高:40
}
});
AppRegistry.registerComponent('MyApp',()=>MyApp);
如果这对调试代码的合理性检查没有帮助,请发布您为
TextInput
配置的样式定义(style.searchBar
),以便我们进行更好的测试。它仍然没有显示。而且,它在android bdw中工作。iOS有什么不同吗?谢谢。成功了。我错过了styles酒店