你将不得不像这样绑定你的函数。
<TouchableOpacity
onPress={this.example.bind(this)}
style={{padding: 10, justifyContent: 'center', flexDirection: 'row', backgroundColor: '#F26525', width: Dimensions.get('screen').width * 0.8, borderRadius: 3, marginTop: 15}}>
<Icon name='refresh' size={20} color='#ffffff' />
<Text style={{fontSize: 16, color: '#ffffff', fontFamily: 'Quicksand-Medium'}}> Try Again</Text>
或者你也可以在你的构造函数中绑定你的函数
constructor(props) {
super(props)
this.example = this.example.bind(this)
}
<TouchableOpacity
onPress={this.example}
style={{padding: 10, justifyContent: 'center', flexDirection: 'row', backgroundColor: '#F26525', width: Dimensions.get('screen').width * 0.8, borderRadius: 3, marginTop: 15}}>
<Icon name='refresh' size={20} color='#ffffff' />
<Text style={{fontSize: 16, color: '#ffffff', fontFamily: 'Quicksand-Medium'}}> Try Again</Text>
或者像这样
<TouchableOpacity
onPress={() => {console.log('Pressed!')}}
style={{padding: 10, justifyContent: 'center', flexDirection: 'row', backgroundColor: '#F26525', width: Dimensions.get('screen').width * 0.8, borderRadius: 3, marginTop: 15}}>
<Icon name='refresh' size={20} color='#ffffff' />
<Text style={{fontSize: 16, color: '#ffffff', fontFamily: 'Quicksand-Medium'}}> Try Again</Text>