重新加载UITableView显示错误? [英] Reloading UITableView shows error?

查看:159
本文介绍了重新加载UITableView显示错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处境很奇怪。当我尝试使用 reloadData()重新加载tableview时,它显示以下错误。 。 。

I am in a strange situation . when i try to reload the tableview using reloadData() it shows the following error . . .


致命错误:在展开可选值时意外发现nil

fatal error: unexpectedly found nil while unwrapping an Optional value

以下是检索输出的Web服务方法

Here is the web service method that retrieves output

func didRecieveOutput(results:NSArray) { 
if results.count != 0 
{ 
userOrders = results as! NSMutableArray 
dispatch_async(dispatch_get_main_queue(), { () -> Void in        
self.orderList.reloadData() })
 } 
}

编辑:我已经检查了我的连接以及委托&数据源 。它适用于静态数据。但是当我调用reloadData()时出现了问题。我对静态数据和动态(来自服务器的数据)也有同样的问题。

Edit : I had checked my connection as well as delegate & datasource . It works fine with static data . But problem came when I called reloadData(). I had the same problem with static data as well as dynamic (data from server).

推荐答案

此错误可能有多种原因。一些常见原因是:

There could be n number of reasons for this error. Some of the common causes are:


  1. 您的 @IBOutlet 为您的 UITableView 未正确连接。

  2. 缺少委托/数据源也可能是一个原因。

  3. reloadData() call。

  4. 在使用某些对象之前,你没有正确检查 nil 。 / li>
  5. 发布获取服务器响应后,您正在创建一个新实例,而不是使用已加载的实例。

  6. 另一个原因可能是您的视图结构是这样的:UITableViewController ---> UIView ---> UITableView,然后'tableView'变为nil你需要调出 [[self.view.subviews objectAtIndex:0] reloadData]; 。参考: Apple论坛

  1. Your @IBOutlet for your UITableView is not properly connected.
  2. Missing Delegate/Datasource could also be a reason.
  3. Your model that feeds data to table views is being modified just before reloadData() call.
  4. You are not properly checking for nil before using some objects.
  5. Post getting server response, you are creating a new instance instead of using the one that was already loaded.
  6. Another reason could be if your view structure is like this: UITableViewController ---> UIView ---> UITableView, then 'tableView' goes nil and you need to call out [[self.view.subviews objectAtIndex:0] reloadData];. Reference: Apple Discussion Forum.

您可以尝试以上情况,但我们可以指出您需要共享表格视图呈现代码和流程所需的错误。

You can try above cases but for us to pin point the error you would need to share your table view rendering code and flow.

这篇关于重新加载UITableView显示错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆