小编J.D*_*Doe的帖子

如何在Prolog中将if转换为完全声明?

这是我的课堂问题之一.

题

我能够用if-else创建我自己的Prolog程序,但我被告知我的程序并不是完全声明的,因为它是Prolog中最基本的原则之一.

这是我的代码

%start with :- go.
is_spicy :-
  write('Do you want spicy? (yes/no)'),
  read(Preference),
  ( Preference == yes -> recommend("Curry"); recommend("Kurma") ).

is_fry :-
  write('Do you want fry food? (yes/no)'),
  read(Preference),
  ( Preference == yes -> recommend("StirFry"); recommend("Chicken") ).

is_chili :-
  write('Do you want chili? (yes/no)'),
  read(Preference),
  ( Preference == yes -> recommend("Sambal"); recommend("Singgang") ).

recommend(Food) :- write('We recommend you '), write(Food).

go :-
  write('Which food type do you prefer? (indian, chinese, malay): '),
  read(FoodType),
  (
    FoodType == indian …
Run Code Online (Sandbox Code Playgroud)

declarative prolog logical-purity

7
推荐指数
1
解决办法
230
查看次数

如何在react-native上自动对焦下一个TextInput

我正在尝试创建一个受密码保护的屏幕.屏幕将使用4个数字输入作为密码.

我这样做的方法是创建一个TextInput组件,并在我的主屏幕中调用它4次.

我遇到的问题是当我键入前一个TextInput的值时,TextInputs不会关注下一个.

我正在为所有PasscodeTextInput组件使用refs(我已被告知这是一种遗留方法,但我不知道其他任何方式,唉).

试过这个方法(没有创建我自己的组件),也没有运气. 方法

图片

index.ios.js

import React, { Component } from 'react';
import { AppRegistry, TextInput, View, Text } from 'react-native';
import { PasscodeTextInput } from './common';

export default class ProgressBar extends Component {
  render() {
    const { centerEverything, container, passcodeContainer,  textInputStyle} = styles;
    return (
      <View style={[centerEverything, container]}>
        <View style={[passcodeContainer]}>
          <PasscodeTextInput
            autoFocus={true}
            ref="passcode1"
            onSubmitEditing={(event) => { this.refs.passcode2.focus() }} />
          <PasscodeTextInput
            ref="passcode2"
            onSubmitEditing={(event) => { this.refs.passcode3.focus() }} />
          <PasscodeTextInput
            ref="passcode3"
            onSubmitEditing={(event) => { this.refs.passcode4.focus() }}/>
          <PasscodeTextInput
            ref="passcode4" /> …
Run Code Online (Sandbox Code Playgroud)

javascript facebook textinput react-native

7
推荐指数
3
解决办法
2万
查看次数

只能在Android的对象上调用Get Object.freeze

我得到Object.freeze只能在对象调用(仅在Android上)。

经过深入研究,我发现这是因为我在不同的文件夹中引用了所有样式,而Android对此并不满意。

Github问题

图片

我的文件夹结构

  • src

    • 行动
    • 货柜
      • Home.js(具有样式)
    • 组件
    • 样式
      • calculateSize.js
      • index.js
  • App.js

  • Router.js(具有样式)

如您所见,模拟器开始抱怨

Router.js: 9
Run Code Online (Sandbox Code Playgroud)

对应于

import styles from './styles'; // Line 9 in Router.js
Run Code Online (Sandbox Code Playgroud)

长话短说,只有当我在要进行样式设置的文件中创建本地StyleSheet变量时,问题才会消失,这很烦人。

有人遇到过吗?我找不到解决方案:(

这是我的样式索引,也许某些方法未定义并且我不知道

计算尺寸

index.js

import styles from './styles'; // Line 9 in Router.js
Run Code Online (Sandbox Code Playgroud)

javascript css android reactjs react-native

6
推荐指数
1
解决办法
2590
查看次数

错误A的窗口不等于B的视图窗口

所以我在两个视图控制器之间执行segue时遇到了问题.

我们打电话给2个视图控制器

答:LoginViewController

B:ViewController

图片

在BI中有一个"Log Out"按钮(它是一个左栏按钮项),当它点击它时触发一个函数,就像这样,并调用dismissViewController并返回A.

@IBAction func logOutButton(sender: AnyObject) {
    let actionController = UIAlertController(title: "Log out", message: "Are you sure you want to log out?", preferredStyle: UIAlertControllerStyle.Alert)

    let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default){UIAlertAction in
        self.prefs.setInteger(0, forKey: "ISLOGGEDIN")
        self.prefs.setInteger(0, forKey: "PERMISSIONTOLOADDATA")
        self.prefs.synchronize()

        print("User logged out")
        socket.disconnect()
        self.dismissViewControllerAnimated(true, completion: nil)
    }

    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default){UIAlertAction in
        print("Test: Log out action cancelled")
    }

    actionController.addAction(okAction)
    actionController.addAction(cancelAction)
    self.presentViewController(actionController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

这里没有错,但是当我在A的文本字段中输入我的ID并单击Login按钮时,它会触发这样的错误:

2016-02-02 17:33:12.879 iCare[3852:190330] <UIView: …
Run Code Online (Sandbox Code Playgroud)

model-view-controller xcode ios segue swift

5
推荐指数
1
解决办法
2020
查看次数

找不到Objective-C Bridging Header部分

我正在研究React Native应用程序,我正在尝试使用名为react-native-socketio的模块.

为了继续使用该应用程序,我需要在Xcode中桥接目标C头,但缺少相关部分.

根据教程 根据教程

Xcode中

我也注意到Xcode中也缺少Swift编译器 - 代码生成部分.

为什么?

xcode objective-c ios swift react-native

2
推荐指数
1
解决办法
3024
查看次数

如何在Swift中找到类数组中的项的索引?

首先,我们都知道找到一个数组的索引很容易,但我找到了一个包含多个结构的数组中的项目索引.

这是我的班级:

class Patient{
private var id: Int
private var name: String
private var gender: String
private var mileage: Double

//global variable
var globalPatientID:Int{
    return id
}
var globalPatientName:String{
    return name
}
var globalPatientGender:String{
    return gender
}
var globalPatientMileAge:Double{
    return mileage
}

init(id:Int, name:String, gender:String, mileage:Double){
    self.id = id
    self.name = name
    self.gender = gender
    self.mileage = mileage
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的阵列:

let AppUserID = prefs.objectForKey("AppUserID")

        for var i=0; i<nou; ++i{
            numberOfUsersExisting = nou

            if (AppUserID as? String == json[0][i]["App_ID"].stringValue){
                print("Assigning …
Run Code Online (Sandbox Code Playgroud)

arrays ios swift swift2

1
推荐指数
1
解决办法
4134
查看次数