Javascript 如何在React Native中调用AlertIOS
我是一名iOS开发人员,但我懂一点javascript。我正在尝试使用AlertIOS,文档api如下Javascript 如何在React Native中调用AlertIOS,javascript,ios,react-native,Javascript,Ios,React Native,我是一名iOS开发人员,但我懂一点javascript。我正在尝试使用AlertIOS,文档api如下 static alert(title: string, message?: string, buttons?: Array<{ text: ?string; onPress: ?Function; }>) 静态警报(标题:字符串、消息?:字符串、按钮?:数组) 我对参数感到困惑。我试着这样写,但它给了我错误。 AlertIOS('Username empty','Please
static alert(title: string, message?: string, buttons?: Array<{ text: ?string; onPress: ?Function; }>)
静态警报(标题:字符串、消息?:字符串、按钮?:数组)
我对参数感到困惑。我试着这样写,但它给了我错误。
AlertIOS('Username empty','Please type your Username',按钮:{{text:'Cancel',onPress:onPress Cancel})
如何正确使用AlertIOS?如果你看一下,就会发现有一个名为AlertIOS
API的静态方法叫做alert
。这意味着你可以这样称呼它:
AlertIOS.alert('Username empty', 'Please type your username', [{text: 'Cancel', onPress: onPressCancel}]);
var {
AppRegistry,
StyleSheet,
View,
AlertIOS
} = React;
请注意,您也不需要buttons数组的“buttons:”前缀-您调用的这部分语法无论如何都是无效的
警报的方法签名是使用类型注释记录的。每个参数的描述如下:
AlertIOS.alert('Username empty', 'Please type your username', [{text: 'Cancel', onPress: onPressCancel}]);
var {
AppRegistry,
StyleSheet,
View,
AlertIOS
} = React;
- 参数名称:参数类型
- 标题,带有字符串类型
- 消息,带有字符串类型(可选)
- 按钮,带有数组类型(可选)
需要
AlertIOS API,可能是这样的:
AlertIOS.alert('Username empty', 'Please type your username', [{text: 'Cancel', onPress: onPressCancel}]);
var {
AppRegistry,
StyleSheet,
View,
AlertIOS
} = React;
希望有帮助。您能发布错误消息吗?谢谢@KevinChen你能告诉我我打电话写对了吗?记得把“AlertIOS”添加到你的反应要求列表中