【发布时间】:2025-12-08 21:50:01
【问题描述】:
您好,我正在尝试在导航器右键中绑定一个函数,
但它给出了错误。
这是我的代码:
import React, { Component } from 'react';
import Icon from 'react-native-vector-icons/FontAwesome';
import Modal from 'react-native-modalbox';
import { StackNavigator } from 'react-navigation';
import {
Text,
View,
Alert,
StyleSheet,
TextInput,
Button,
TouchableHighlight
} from 'react-native';
import NewsTab from './tabs/news-tab';
import CustomTabBar from './tabs/custom-tab-bar';
export default class MainPage extends Component {
constructor(props) {
super(props);
}
alertMe(){
Alert.alert("sss");
}
static navigationOptions = {
title: 'Anasayfa',
headerRight:
(<TouchableHighlight onPress={this.alertMe.bind(this)} >
<Text>asd</Text>
</TouchableHighlight>)
};
render() {
return(
<View>
</View>
);
}
}
并得到这样的错误:
undefined 不是对象(评估 'this.alertMe.bind')
当我在渲染函数中使用此方法时,它工作得很好,但在 NavigatonOption 中我无法处理它。我能做些什么来解决这个问题。
【问题讨论】:
标签: react-native react-navigation react-navigation-stack