i am using core data...my table view does not reload say if i add a new row to the table. until i terminate the app and re open it...im calling reloadData in my root controller viewwillappear method... any help would be appreciated
thanks in advance
I am guessing you are using a NSFetchedResultsController? If you are not then you need to be with a UITableView. Once you do, make sure you have your UITableViewDatasource configured as the delegate to the NSFetchedResultsController. Once you do that, you will not need to call -reloadData at all because the NSFetchedResultsController will monitor changes in the NSManagedObjectContext and update the UITableViewDatasource as needed via the delegate methods.
Related
Using NSFetchedResultsController delegate method controller
(_:didChange: at:for:newIndexPath:), between tableView.beginUpdates() in controllerWillChangeContent(_:) and tableView.endUpdates() in controllerDidChangeContent(_:), results in objects with nil properties (including the uniqueIdentifier, which is normally set in awakeFromInsert()) being created when merging changes from different devices, and related crash. The problem doesn't occur when only the controllerDidChangeContent(_:) delegate method with tableView.reloadData() is implemented instead.
Any advice on how to eliminate this problem would be appreciated.
Adding tableView.reloadData() in controllerWillChangeContent(_:) just before beginUpdates() seems to solve the problem. It ensures that data in the tableView is in sync with that in the fetchedResultsController (FRC) before the tableView is modified by the FRC delegate methods.
I have something like this:
A. UICollectionView1 with FRC1 and FRC_Search_1 for UICollectionView_Search_Results_1
B. UICollectionView1 with FRC2 and FRC_Search_2 for UICollectionView_Search_Results_2
C. UICollectionView1 with FRC3 and FRC_Search_3 for UICollectionView_Search_Results_3
D. UICollectionView1 with FRC4 and FRC_Search_4 for UICollectionView_Search_Results_4
.
.
.
Idea was to use NSFetchedResultsControllerDelegate for updating Collection Views. But if I implement it at both A and B, after one update, both implementation will be called. I don't understand why is this happening. Is it because both FRCs are pulling from same entity or because they have same context or something else?
What is the best approach to solve this?
EDIT:
#Tuslareb
I have 2 UICollectionViewControllers with seperate classes. Each has it's own FRC, collectionView and Delegate implementation. If FRCs looks the same ( same entity,predicate...) both delegates are activated when I update only one collectionView in one collectionViewController.
Problem occurs if those 2 collectionViews are different. Then indexPaths are different, and updating produces errors and stops app.
This is probably the way it works, core data is observing type of FRC but not objects itself. But I wanted to be sure.
When a delegate is set for a FRC, the FRC will receive change notifications from the context. Then, the FRC will notify the delegate whose methods will update the collection (or table) view. So, as you already did find out yourself, any changes in the context will notify the FRC delegate when the FRC object is 'alive'.
This answers at least one part of your question. To solve it, you will need to obtain a reference to the collection view that was changed and change the delegate methods in a way that they will only be executed for the view that was changed.
I have JSON web-service and my task is to parse the web service and store the data into UITableview.
I am parsing the web service using NSURLConnection methods.
After parsing the web-service i got the response what I wanted .
But the issue is that my UIViewController is calling UITableView Delegate and Datasource methods first and then it calls web-service so my UITableView doesn't get any response.
Even though I call the web-service first it calls all the UITableView Delegate and Datasource methods first and then web-service so my table view doesn't get any response.
After calling the web-service i get perfect response.
So if somebody knows any solution please help me.
Thank you.
The other answers in this thread should solve your problem.
However, if you find that [self.tableView reloadData] isn't refreshing the data in your UITableView, check out my suggestion on this thread:
Fails to call delegate/datasource methods in UITableView implementation
I'm not sure if this is a quirk with iOS 8, but I've had a few occassions where just setting the table's dataSource and delegate in the code hasn't been enough.
After you get your response and populate dataSource just call
[self.tableView reloadData];
Just set the data-source and delegate of table view in the delegate of the web-service delegate or where you get the response and reload the table view.
I'm using a UITableView which loads data from a server. I need to use async ASIHTTPRequest, which is in a separate .m.
How could I force to reload the table data when the requestFinished:request is called?
Thanks!
You can just send the data that needs to be loaded into the TableView by passing it between files. and then finally call a different method of inside the table view that implements the command [self.tableview relaodData];
Update:
What i see from your comments is that the you have a tableView CONtroller or someform of controller that loads the data by calling another class that holds the ASIHTTPrequest/ ansynchrinous requsts. now You have also told me that the TableView Also hold a UIViewController in each cell which i Dont think is a good idea you could go with a custom cell method have a look at this 4 part tutorial... now and the data that needs to be loaded into the TableView is loaded by TableViewController by some method wither it be each cell or something... so after you are able to get the data just inside the tableViewController just Call the [self.tablebview reloadData] inside the TableViewController which is the parent of the TableView there is no need to call in the other methods.
Finally solved with observers although when the app is completely closed won't work. I'll think in something.
Thanks
I have a table view which i want to populate with the results (XML) of my call to a web service.
The NSURLConnection and NSMutableURLRequest that are doing the setup for this are currently in my -viewDidLoad method, and i also have all of my UITableView delegate methods in my .m file too.
The data is being returned and added to my array correctly. My problem is (i think) that the UITableView methods are being called before any data has been returned from the web service, which is why my table view is always blank.
How can i call the methods in the right order (if this is even the problem)...
Are you calling reloadData on the tableview once you've repopulated the array? You need to let it know that you have new data.
UITABLEVIEW *mytableview=[[UITABLEVIEW alloc]init];
[mytableview reloadData];
Yes you are right; the UITABLEVIEW delegates are called before the web service. So you have to call those delegates again so try reloading the data. Works perfect for me. reload table when u have something returned from the webservice. store it in NSArray or whatever and then reload table.
Check out Apple's SeismicXML code example on the developer.apple.com/iphone site. It shows how to use NSURL, NSXMLParser, and a TableView to do just this type of thing.