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];
}
}
Related
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.
Summary of the issue:
When I am loading some data into my iPhone application from a webservice, it populates the tableview two times with double number of records. I found that Viewdidload method is called two times causing this issue.
Scenario
From the first view I parse the webservice and collect the data into an array object.
This array object is being used by the second view to populate the tableview.
I am wondering what is behind reloading of the page causing the tableview has double number of records. Hope somebody can give me a hint.
You may want to consider calling applicationDidFinishLaunchingWithOptions in your app delegate, as this is only called during launch.
Thanks for the tips. What I found the issue was the way adding the view. i replaced [self.view addSubview:trlist.view] with [self presentModelViewController:trlist animated:NO]; and now it loads only one time.
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 am developing one navigation based application. All data required for each screen are getting downladed from webserver. I am starting downloading in viewDidLoad method. ALl downloadinh is happening asynchroniously and respective viewcontroller will receive data through delegate pattern. Now my question is in case new viewcontroller is getting pushed on navigation stack or current view controller is getting popped off so fast before data will get received, how we will handle this situation? We do not want to block UI so user can move back or forward. I used notification mechanism to detect particular view controller (one who receive data ) is alive or not , but it seems like not a concrete solution. So basically I want to detect receiver is appropriate for receiving downloaded data before I make a call to its delegate method.
Any pointer related to it is highly appreciable.
Thanks!
Nilesh
I think the dataSource pattern is more appropriate.
1) Create a datasource (singleton or attached in your app delegate)
2) Implement a method dataWithPredicate: (or just data)
3) Notify your viewController (with NSNotificationCenter) when a data is updated
4) Reload data from the controller (with dataWithPredicate: call)
Another way is to use core data for that. CoreData generate all the notification and do the job for you.
I have data being refreshed in a modalViewController and when that data gets refreshed, the parent controller needs to refresh its data as well. I tried doing a [tableView reloadData]; but it didn't work properly since the actual array values aren't being refreshed. Is there a way for me to reload a controller without the user seeing any animation?
Thanks for any help!
Are you refreshing the data off the main thread? If so, you need to call the reloadData method using the following method:
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait
So for a tableView it would be something like:
[tableView performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:NO];
The underlying view can get released while the modal view is showing, so you shouldn't try to modify it directly. Instead, you can use the viewWillAppear: method on the main view controller to make any necessary updates.
I'm not sure what you mean that "the actual array values aren't being refreshed". How the two view controllers exchange data depends a lot on what you are trying to accomplish. If the modal view is only used in one place, the main controller can access its properties directly. Or maybe you want a dedicated class to hold the state... Again, depends on the context.