-1

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

Karan Alangat
  • 1,886
  • 2
  • 23
  • 55

2 Answers2

1

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.

Abhinav
  • 36,284
  • 39
  • 178
  • 301
  • It does not matter whether data is assigned to dictionary or array. For any further assistance from anyone on SO community you would need to share your code. – Abhinav Sep 21 '15 at 12:44
0

Solution found !!!! :)

Thanks to Abhinav for giving me the thread even though his suggestion failed.

var array : NSArray = self.view.subviews
array.objectAtIndex(0).reloadData()

I got the same error for this also. So I tried this and worked

var array : NSArray = self.view.subviews
array.objectAtIndex(2).reloadData()

Here in this array my tableview is at 2nd index. So my suggestion is to check the array to identify the tableview object first and use the index.

Community
  • 1
  • 1
Karan Alangat
  • 1,886
  • 2
  • 23
  • 55