【发布时间】:2015-10-03 15:30:29
【问题描述】:
我正在使用NSRange 将 100 个数组分成 10 个并将它们存储在数组数组中。当我向下滚动到 UITableView 中的最后一部分并且我正在使用索引 UITableView 时,出现以下错误。
* 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[__NSArrayI objectAtIndex:]:索引 18446744073709551615 越界 [0 .. 9]'
以下是我的代码:
var tableData : NSMutableArray!
var mutA = NSMutableArray()
var indexOfNumbers = [String]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
tableData = [
// 100 lines of string array of different starting letter
]
let indexNumbers = "0 10 20 30 40 50 60 70 80 90 100"
indexOfNumbers = indexNumbers.componentsSeparatedByString(" ")
for (var i = 0; i < 9; i++)
{
var halfArray : NSArray!
var theRange = NSRange()
theRange.location = i*10;
theRange.length = tableData.count / 10
halfArray = tableData.subarrayWithRange(theRange)
mutA.addObject(halfArray)
}
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return indexOfNumbers.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.textLabel?.text = mutA[indexPath.section][indexPath.row] as? String
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
return indexOfNumbers
}
func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
let temp = indexOfNumbers as NSArray
return temp.indexOfObject(title)
}
我不知道发生了什么。
【问题讨论】:
-
哪一行导致错误?
-
仅供参考 - 问题标题和错误完全不同。
-
不是任何特定的行,它显示的是 e
App delegate! -
在调试器中添加异常断点,使其停在导致问题的行上。
-
添加异常断点,查看代码在哪一行崩溃。
标签: ios swift uitableview