Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
697 views
in Technique[技术] by (71.8m points)

ios - Reloading UITableView shows error?

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

fatal error: unexpectedly found nil while unwrapping an Optional value

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() })
 } 
}

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).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...