2016-06-22 50 views
3

我有一個TextInput組件中反應本土的TextInput在反應機iOS

<TextInput 
      style={styles.searchBar} 
      value={this.state.searchText} 
      onChange={this.setSearchText.bind(this)} 
      placeholder='Search State' 
     /> 

這是工作在android系統完全正常,但文本框不會在iOS應用中展示。而且,沒有什麼可以找到問題所在。

任何人都可以幫助解決這個問題嗎?

回答

0

你應該給了TextInput高度和寬度,以顯示的TextInput爲:

<Textinput style={{height:200, width:300}}/> 
+0

它還沒有出現。並且,它在android bdw中工作。對iOS來說它有什麼不同? –

7

下面是一個說明需要提供用於在iOS的TextInput部件的高度的代碼示例。在docs中沒有明確說明,但仔細查看它會發現代碼示例的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); 

如果不能在調試代碼的完整性檢查幫助,請張貼樣式定義(styles.searchBar)已配置對於你的TextInput,所以我們可以給出一個更好的測試。

+0

謝謝。有效。我錯過了styles屬性 –

相關問題