【问题标题】:React-native - Alert.alert, unrecognized selector sent to instanceReact-native - Alert.alert,无法识别的选择器发送到实例
【发布时间】:2018-05-14 09:35:55
【问题描述】:

由于未知原因,我的 Alert.alert 拒绝工作。我基本上是在重用它之前工作的代码。得到错误:

异常 NSArrayl 长度;无法识别的选择器发送到实例 在 targer 上调用 alertWithArgs 时抛出 0x170623440 带有参数的警报管理器。

谢谢

acceptFriendRequest(friendsName){
    Alert.alert(
      friendsName + ' wants to add you',
      [
        {text: 'Decline', onPress: () => console.log('Cancel Pressed'), style: 'cancel',
      },
      {text: 'Accept', onPress: () =>  this.confirmFriendRequest(this), style: 'accept'},

    ],
    )
  }

【问题讨论】:

    标签: javascript reactjs react-native


    【解决方案1】:

    您需要传递第二个参数 (the alert body message),如果您不需要正文消息,可以使用 undefined/null

    Alert.alert(`${friendsName} wants to add you`, undefined, [
      {
        text: 'Decline',
        onPress: () => console.log('Cancel Pressed'),
        style: 'cancel',
      },
      { text: 'Accept', onPress: () => this.confirmFriendRequest() },
    ]);
    

    由于bug in RN,您可能需要完全关闭应用并在应用更改后重新启动它。

    另请注意:

    • style: 'accept' 无效,将被忽略。
    • 您无需将this 作为参数传递给this.confirmFriendRequest()

    【讨论】:

    • 在这里拯救我的是您对完全重启应用程序的引用。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 2012-07-24
    相关资源
    最近更新 更多