在应用程序中,我拉取一个 JSON 数组并使用它来填充 UITableView:
class TableViewController: UITableViewController, NSURLConnectionDelegate {
var tableData: [AnyObject] = []
// ...
func connectionDidFinishLoading(connection: NSURLConnection!) {
var dataAsString = NSString(data: data, encoding: NSUTF8StringEncoding)
var err: NSError
var json = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
// After parsing JSON...
tableData += json as Array
tableView.reloadData()
tableView.scrollToRowAtIndexPath(NSIndexPath(index: tableData.count - 1), atScrollPosition: UITableViewScrollPosition.Top, animated: true)
}
// ...
}
最后一行调用scrollToRowAtIndexPath
,产生一个信号SIGABRT。注释掉该行可以修复它。我对 iOS 开发相当陌生,因此我们将不胜感激。提前致谢。
最佳答案
您应该使用以下代码:
NSIndexPath(forRow: tableData.count - 1, inSection: 0) //O in section: if tableView has only one section
而不是:
NSIndexPath(index: tableData.count - 1)
传递给 TableView 的索引路径必须恰好包含两个指定节和行的索引。
关于ios - 调用scrollToRowAtIndexPath时的SIGABRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25457251/