Reloading UITableView shows error?

后端 未结 2 1676
渐次进展
渐次进展 2020-12-20 10:38

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

fatal error: unexp

相关标签:
2条回答
  • 2020-12-20 10:59

    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.

    0 讨论(0)
  • 2020-12-20 11:03

    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.

    0 讨论(0)
提交回复
热议问题