Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 启用禁用快速滑动手势_Swift_Swipe Gesture_Ios9.1 - Fatal编程技术网

Swift 启用禁用快速滑动手势

Swift 启用禁用快速滑动手势,swift,swipe-gesture,ios9.1,Swift,Swipe Gesture,Ios9.1,我的功能如下 我试图在数组达到极限时禁用文本。 我得到一个数组超出范围的错误。当array1.count等于swipcount时,我可以使用什么类型的条件来禁用数组。 这是我的代码: let array1 = ["a","b","c","d"] func getRandom1() { for var i = 0; i < array1.count ; i++ { array1.shuffle1() } } func getText1() {

我的功能如下 我试图在数组达到极限时禁用文本。 我得到一个数组超出范围的错误。当
array1.count
等于
swipcount
时,我可以使用什么类型的条件来禁用数组。 这是我的代码:

 let array1 = ["a","b","c","d"]

 func getRandom1() {
    for var i = 0; i < array1.count ; i++
    {
        array1.shuffle1()
    }

}

func getText1() {

    self.display.text = "\(array1[i++])"
    swipeCount++
}

func getTextBack() {


    self.display.text = "\(array1[i])"

}


func handleSwipes(sender:UISwipeGestureRecognizer) {

if (sender.direction == .Right)
{

    if swipeCount != array1.count
    {
        getText1()
    }


    else

    {
        getTextBack()
    }

  }


  }
让数组1=[“a”、“b”、“c”、“d”]
func getRandom1(){
对于var i=0;i
更改此行:

if swipeCount != array1.count

func handlesweeps(发送方:UISweepGestureRecognitor){
if(sender.direction==.Right){
设a计=array1.count-1
如果swipeCount
array1包含所有文本,如let array1=[“a”、“b”、“c”、“d”]@SabhaySardana:我在这里没有看到任何可能导致
array超出范围的代码。请告诉我们如何定义
getText1()
notText()
func getText1(){self.display.text=“\(array1[I++])”swipcount++
func noTextBack(){self.display.text=“\(array1[i])”}
在哪里定义了
i
呢?使用
array1[i++]
。检查以确保在递增之前有下一个元素。我以前尝试过,我刚刚更新了我的代码。您可以在我的编辑中看到:)
if swipeCount < array1.count - 1
func getText1() {
    self.display.text = "\(array1[swipeCount++])"
}

func getTextBack() {
    self.display.text = "\(array1[swipeCount])"
}
func handleSwipes(sender:UISwipeGestureRecognizer) {

if (sender.direction == .Right) {
   let aCount = array1.count - 1

   if swipeCount < aCount
{
    getText1()
}


else

{
    getTextBack()
}

}