I've UItableView in UIViewController and database connected to UItableVIew it loads data from sqlite3 database but its not Showing new content when i add new content to database until i relaunch the application. I tried below code
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.LengthTableFrom reloadData];
}
when you add new content at that after that get all data again and also add this line after get all data
[self.LengthTableFrom reloadData]
i hope it will work fine..
:)
I think when you are adding or editing your data to database.
And in viewController where tableView exist
In viewDidLoad you are fetching data from database & saving into array. Reloading list in viewWillAppear. For fist time it works fine, after when you add new content to your database your array for tableView will not be having new content.
For testing you can have your data fetching from database in your viewWillAppear view controller, to check it works fine.
In real time you have to add the new content to database get the ref id, and add the new content with ref id to your array for tableView.
It's simply mean that you are not calling the [self.LengthTableFrom reloadData] method properly.
You should place this code [self.LengthTableFrom reloadData] just below the code where you fetching the database content .
i hope it'll work fine.
Related
I am fetching some data from the WCF webservice in a separate thread after each 30 seconds...
and I want something like that a view controller having table view keeps on getting updated whenever i receive fresh data...how can I achieve that...I tried notification but that requires me to come on that particular view controller....
Any advise?
Thanks,
You need not to be on the controller when you send notification.
You can achieve it also using delegates, just called the method of the controller which reload the data of table view when you receive the data.
I hope I have understood your question correctly: You want to get data from a webservice and then update a tableview once you have retrieved the data.
Here's some mockup code:
wcfWebserviceFetcher.tableViewDelegate = mainTableView;
Now in the wcfWebserviceFetcher:
-(void) dataFetchDone {
if(tableViewDelegate!=nil) {
tableViewDelegate.data = self.wcfWebserviceDataResult;
[tableViewDelegate reloadData];
}
}
Given this Core Data Model: Photographer <-->>Photos.
After adding a Photographer via a Modal View, the tableView of Photographers updates accordingly.
The problem is, that it doesn't do the same for Photos. I can add a Photo via a Modal View, and the tableView of Photos for that particular Photographer does not update immediately. Once I navigate back to the tableView of Photographers and select the same Photographer again, it updates as expected.
How can I get the tableView of Photos to update as soon as the Modal View(where the user added the object) gets dismissed?
Where modal view dismiss try to use:
[tableView reloadData];
Try
[tableview reload];
method after getting new data.
Check your error variable if it contains an error.
You directly assign the result of -executeFetchRequest:error: to an ivar (photographerPhotosArray). This either leaks or causes an immediate release.
Consider switching to NSFetchedResultsController since it helps you a lot.
Check your array first is it fill or empty? try with NSLog and check it. if it exist then reload your table
I need your help, maybe its something silly but I can't find the error.
I have a table view and an add button, when its clicked I show a modal view with a little form, when save button is pressed I send the data to the TableView controller to show it, also I'm using NSUserDefaults to save this data in an array.
My problem comes when, for example, I add 2 new rows and delete 1 of them, then when I add another, it shows the last row I delete instead of showing the one I just add.
I'm doing the saving and reading this way:
in viewDidAppear I read the NSUserDefaults and get the data if exist.
in the method that catches the data from the ModalView I save to userdefaults.
in commitEditing method I read userdefaults and then delete the row from the array and from the table and then save this change in userdefaults.
I don't know what I doing wrong, Can anybody help me with this?
Use [self.tableView reloadData]; in the viewWillAppear of that class. You can also reference that class in another view controller, create an object for it and call [classObject.tableView reloadData];
Always remember to reload the tableView after an add operation or a delete operation.
Don’t use NSUserDefaults to act as the direct datasource of a table. Store it in an intermediate model. It’ll be a LOT easier to debug that way.
If you’re having trouble keeping your model synced with the user defaults, call [[NSUserDefaults standardUserDefaults] synchronize] whenever you alter them.
Also, make sure you’re not making some mistakes in your table cell reuse. You might be seeing old data if you have a customer UITableViewCell class and you’re not correctly implementing -prepareForReuse.
I have a UITableview that I load with data async so the tableview might appear without data.
I have tired the ReloadData method but the tableview remains empty until I scroll the tableview, suddenly the data appears.
The same thing happens when I load a tableview as a detailedview and switching between items, the previoud items data appears first and as soon as I scroll in the table view it shows the correct data.
My guess is that the ReloadData method works just fine, but I need to redraw the tableview somehow, any suggestions on how to solve this?
/Jimmy
You said you're populating content asynchronously but did you invoke the reloadData in the context of the main thread ? (and not via the thread that populates the content)
Objective-C
[yourUITableView performSelectorOnMainThread:#selector(reloadData)
withObject:nil
waitUntilDone:NO];
Swift
dispatch_async(dispatch_get_main_queue(), { self.tableView.reloadData() })
Monotouch
InvokeOnMainThread(() => this.TableView.ReloadData());
Yonels answer is perfect when your view is currently visible to the user (e.g: User presses a reload button which populates your UITableView.)
However, if your data is loaded asynchronously and your UITableView is not visible during the update (e.g: You add Data to your UITableView in another View and the UITableView is displayed later by userinput), simply override the UITableViewController's viewWillAppear method.
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.tableView reloadData];
}
The positive effect is that your UITableView only reloads it's data once when the user actually want's to see it, not when new items are added.
I had the similar issue today(Storyboard in iOS 7.0).
I was using table View inside a UIViewController.When the view was loaded everything was working fine; all the delegates were getting called.However ; When the underlying dataSource(in my case,Array) was modified; the visible table rows were not getting updated.They were updated; only when I was scrolling the table view.
Tried everything; calling reloadData on Main thread;calling reload in ViewWillAppear; nothing worked.
The issue that I found ; was that I had not made the connection in storyboard; for the table view with the reference Outlet.The dataSource and delegate were set though.
I did not think that it could be the issue; as everything was working fine at the first go.
Hope it helps someone.I had some terrible time to find this out.
I guess it wasn't reloaded.
When you scroll the cells to out of screen, then…
tableView: cellForRowAtIndexPath:
…will be called. So it will be reloaded.
I guess UITableView variable is not validated.
If you use UITableView as a main view, you can try this.
[self.view reloadData];
or
[self.tableView reloadData];
Swift 4:
DispatchQueue.main.async { self.tableView.reloadData() }
After somewhat naively copying in yonel's solution and calling it good I realized that calling performSelectorOnMainThread:withObject:waitUntilDone: fixed the symptom, but not the problem. The bigger problem is that you are making UI updates while still in the context of the asynchronous or background thread.
This is what my code looked like:
dispatch_queue_t queue = dispatch_queue_create("com.kyleclegg.myqueue", NULL);
dispatch_async(queue, ^{
// Make API call
// Retrieve data, parse JSON, update local properties
// Make a call to reload table data
});
When it should look like this:
dispatch_queue_t queue = dispatch_queue_create("com.kyleclegg.myqueue", NULL);
dispatch_async(queue, ^{
// Make API call
// Retrieve data, parse JSON, update local properties
dispatch_async(dispatch_get_main_queue(), ^{
// Now make the call to reload data and make any other UI updates
[self.tableView reloadData]
});
});
If the only thing you need to do is call [self.tableView reloadData] it's probably fine to use performSelectorOnMainThread:withObject:waitUntilDone: since it accomplishes the same goal, but you should also recognize what's happening in the big picture. Also if you are doing more UI work than just reloading the table then all of that code should go on the main queue as well.
Reference: A concise example of using GCD and managing the background vs. main thread.
How do I have a UITableView be notified that the data it is using is new and all old data/cells should be flushed.
I have a search bar that will cause the UITableView to be refreshed when new queries are entered.
An example would be:
[myTableView reloadData];