ios - 调用scrollToRowAtIndexPath时的SIGABRT

标签 ios uitableview swift

在应用程序中,我拉取一个 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/

相关文章:

ios - 是否可以延迟 iPhone 检测运动,直到 View 从屏幕上消失?

ios - 如何在表格 View 中相互交换两个自定义单元格?

ios - Swift:通过能够在 defer 语句中捕获返回值来简化调试

swift - 如何将字符串拆分为 [String] 而不是 [Substring]?

ios - swift : how to detect the error type using the debugger?

javascript - 移动 safari(和 UIWebView)上的表情符号缩小

ios - 在 Apple-Push-Notifications 的应用程序静音

iphone - 在 UITableView 单元格中显示 JSON 对象 - 应用程序崩溃

ios - UISearchController 过滤器 Swift

ios - Swift - 加载外部数据的可变范围