【发布时间】:2015-12-04 19:34:51
【问题描述】:
我的功能是下面的那个
我试图在数组达到其限制时禁用文本。
我收到数组超出范围的错误。当array1.count 等于swipeCount 时,我可以使用什么类型的条件来禁用数组。
这是我的代码:
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()
}
}
}
【问题讨论】:
-
array1 包含所有文本,例如 let array1 = ["a","b","c","d"]
-
@SabhaySardana:我在这里没有看到任何可能导致
array out of range的代码。请告诉我们getText1()和notText()是如何定义的。 -
func getText1() { self.display.text = "\(array1[i++])" swipeCount++ }func noTextBack() { self.display.text = "\(array1[i])" } -
i定义在哪里? -
array1[i++]超出了您的范围。在递增之前检查以确保有下一个元素。
标签: swift swipe-gesture ios9.1