2016-01-21 62 views
1

我在我的列表视图做了一个部分标题响应状态的变化,但我意识到我需要它被修复。但是将其从renderHeader更改为renderSectionHeader时,它是固定的,但不再响应状态更改。反应原生ListView与固定部分标题,可以更新

<ListView 
     dataSource={this.state.dataSource} 
     renderHeader={this.renderHeader} 
     renderRow={this._renderRow} 
    /> 

renderHeader: function() { 
return (
    <View> 
    <Text>{this.state.header}</Text> 
    </View> 

以这种方式,如果状态发生改变,文本(或任何它)将相应地更新。但是当滚动列表时,标题不固定。

<ListView 
     dataSource={this.state.dataSource} 
     renderSectionHeader={this.renderSectionHeader} 
     renderRow={this._renderRow} 
    /> 

renderSectionHeader: function() { 
return (
    <View> 
    <Text>{this.state.header}</Text> 
    </View> 

随着代码作为上述然而,滚动时但使改变时注明他们奇怪,因为它们与普通报头做不在节头更新节头被固定在适当位置。

回答

1

如果您使用renderSectionHeader来呈现标题,则需要使用cloneWithRowsAndSections而不是cloneWithRows

Here是一个很好的讨论如何实现这取决于你的数据。

Here是在GitHub上执行的cloneWithRowsAndSections

+0

如果使用cloneWithRowsAndSections设置它,它也不起作用。无论如何,部分标题不响应状态更改,但标题确实.... – Hasen