import ViewPager from 'react-native-viewpager';
constructor(props){
super(props);
this._renderPage = this._renderPage.bind(this);
this._renderRowSablon = this._renderRowSablon.bind(this);
this.PageChange = this.PageChange.bind(this);
this.count = 0;
this.state = {
count: 0,
info : this.props.values,
page: 0,
pages:pages,
}
}
PageChange(x){
switch(x){
case 'next':
if( this.state.count< (this.state.info.sayfa - 1) ){
this.viewpager.goToPage(this.state.count + 1);
this.setState({count: this.state.count+ 1});
}
break;
}
}
render(){
<View style={{flex:1}}>
<ViewPager
ref={(viewpager) => {this.viewpager = viewpager}}
dataSource={this.state.dataSource}
renderPage={this._renderPage}
onChangePage={this._pageChange}
isLoop={false}
renderPageIndicator={false}
locked={true}
autoPlay={false}/>
</View>
<View style={{flex:1}}>
<TouchableHighlight onPress={() => { this.PageChange('next'); }}>
<Text>Next</Text>
</TouchableHighlight>
</View>
}
清除setState函数后,正在进行页面更改。添加setState函数时(如上所述)setState可以工作,但页面更改(gotoPage)不起作用。不显示错误/警告问题究竟是什么?
答案 0 :(得分:0)
您似乎超出了范围。当使用箭头功能时,&#39;这个&#39;的范围成为词汇。
尝试更改<TouchableHighlight onPress={() => { this.PageChange('next'); }}>
到<TouchableHighlight onPress={this.PageChange('next')}>
看到这个问题: React-Native: Cannot access state values or any methods declared from renderRow