如何在不更改React Native中的路由的情况下更改NavigatorIOS的标题
我的应用程序中有导航器和TabBarIOS。我想在选择选项卡时更改当前路线的标题 第一种方法不起作用 在创建NavigatorIOS时,我在状态对象中使用了一个变量,但更新状态并没有更改标题。(即使再次调用渲染)如何在不更改React Native中的路由的情况下更改NavigatorIOS的标题,ios,react-native,Ios,React Native,我的应用程序中有导航器和TabBarIOS。我想在选择选项卡时更改当前路线的标题 第一种方法不起作用 在创建NavigatorIOS时,我在状态对象中使用了一个变量,但更新状态并没有更改标题。(即使再次调用渲染) onTabChanged:函数(标题){ 这是我的国家({ 选定选项卡:标题, }); }, render(){ 返回( ); }, 第二种方法不起作用 我还尝试更新导航器的状态,我称之为nav。导航器的状态中有一个routeStack对象,它保存一个路由项目数组。因此,我通过Nav
onTabChanged:函数(标题){
这是我的国家({
选定选项卡:标题,
});
},
render(){
返回(
);
},
第二种方法不起作用
我还尝试更新导航器的状态,我称之为nav。导航器的状态中有一个routeStack对象,它保存一个路由项目数组。因此,我通过NavigatorIOS的setState更新了数组,但它也不起作用
第三种方法不起作用
我试图将标题从目标C更改为本机模块,但我无法从NSObject访问特定的导航栏
我希望有人能帮上忙。我想你应该可以用
navigator来做这件事。替换,但目前标题的替换似乎已经中断:
顺便说一句,您还可以通过以下代码更改NavigatorIOS的颜色
var app = React.createClass({
getInitialState: function() {
return {
shadowHidden: false,
barTintColor: '#f04f46',
titleTextColor: '#fff',
tintColor: '#fff',
}
},
_navigator : function(navigatorProps){
this.setState(navigatorProps);
},
render: function(){
return <NavigatorIOS ref='nav' style={styles.container}
shadowHidden={this.state.shadowHidden}
barTintColor={this.state.barTintColor}
titleTextColor={this.state.titleTextColor}
tintColor={this.state.tintColor}
translucent={false}
initialRoute={{
title: title,
component: component,
passProps: Object.assign({
navigatorHook: this._navigator,
}, this.props),
}}
/>;
}
});
不。我不能。我计划用Navigator取代NavigatorIOS,但我现在不在做那个项目。导航器更灵活。
var route = this.props.navigator.navigationContext.currentRoute;
route.title = "newTitle";
route.rightButtonTitle = "newRightButtonTitle",
route.onRightButtonPress = () => {
;
};
this.props.navigator.replace(route);
var app = React.createClass({
getInitialState: function() {
return {
shadowHidden: false,
barTintColor: '#f04f46',
titleTextColor: '#fff',
tintColor: '#fff',
}
},
_navigator : function(navigatorProps){
this.setState(navigatorProps);
},
render: function(){
return <NavigatorIOS ref='nav' style={styles.container}
shadowHidden={this.state.shadowHidden}
barTintColor={this.state.barTintColor}
titleTextColor={this.state.titleTextColor}
tintColor={this.state.tintColor}
translucent={false}
initialRoute={{
title: title,
component: component,
passProps: Object.assign({
navigatorHook: this._navigator,
}, this.props),
}}
/>;
}
});
this.props.navigatorHook({tintColor: 'red'});