TableView is not showing data? - iphone

I have place this question before on following link with code & screenshot.
TableView is not loading data?
Now I came to know my tableview is loading data in tableview cell but not showing/displaying it. I have one Model View Controller in my project. The ModelView controller get called from Mapviewcontroller screen through Search Button. After resigning the Model view controller I can see the data in tableview. (It means when I move to next controller and back to previous tableview.. my tableview shows data in it.)
Here I my data get visible in tableview only after resigning the modelview controller.....
Everything works fine. I just want to know how should I display the tableview data as soon as web-service get called on first screen itself???

Put [_tableView reloadData]; at the end of the method that calls the web-service, or the one that populates the markers array.

If you are manipulating table data in an asynchronous Block,
pass a reference of the tableview to the method implementing the block, and remember to call
[tableview reloadData];
within the block, and not out outside

Related

Updating the TableView inside one of the bars in UITabBarViewController when something happens inside the other bar

I have a two tabbed application. The first tab is a NavigationController that has a few TableViewControllers in it. The second tab is also a NavigationController that has a TableViewController in it.
What I'm trying to achieve is: When someone clicks on a button in the TableView inside first tab, I want to add the the clicked row to the TableView inside the second bar.
I'm already saving the information when it is clicked to NSUserDefaults. When I quit the app and restart, the second bar shows the updated info. But it doesn't show the updated rows if I switch to it while the application is running.
How can I make the second bar reload/update dynamically with the updated rows when someone does sth in the first bar?
I've called [self.navigationController parentViewController] successfully to get the tabBarViewController, which is the highest level, when the the tableview in the first bar changes. How can I get to the TableView inside the NavigatinController inside the second tab from there to have it update itself? Or should I be doing this another way?
Thanks.
i think you can call reloadData in second bar's view controller function
-(void) viewWillAppear:(BOOL)animated
{
[tableView reloadData];
}
You could call the reloadData method on the UITableView within that TableViewController. Honestly, I think you should be using CoreData but I don't know enough of the structure of your data so... try that?

Reload data in UItableview using a button

I want to add a refresh button in UINavigationBar that refreshes the entire table contents. Nothing happens when i click on the refresh button.
I searched google and found that reloadData method refreshes the tableview so I tried using it.
Are you sure your tableView outlet is linked correctly to your tableView property in Interface Builder ?
Is your internal datasource `refreshed' before you call reloadData?
-[UITableView reloadData] tells the table view to request again from you the number of rows in the table, and the cells at each section and row. It's up to you to update your internal data structures as appropriate. So in this case, your IBAction should call your own method to refetch the data from the server.
A few other notes:
Method names should have leading lowercase.
-initWithContentsOfURL: is blocking. This can hang your program for a long time. You should be using asynchronous fetching here (generally with NSURLConnection).
make sure you have the tableView outlet hooked up to the tableView.

iPhone - UITableViewController and Core Data rows repeating in tableView

I am new to Cocoa and Core Data and I've encountered a weird problem. I successfully created the Core Data model, imported the data, made the UI (Navigation controller, tableViewController with searcDdisplayController) but now I'm stuck at one problem. If I implement a UITableViewController (with no UITableView in the nib file), the results fetched from fetchedResultsController are weird - the row count is correct (500 rows), but they are repeating themselves - only 8 different rows.
However, I was able to fix this problem by adding #synthesize tableView; in the .m file.
Then i encountered another problem - when i click on a row and push the details view, then click the back button on the Navigation Controller, the selected row in the tableView is still selected.
I hope I am being clear on what's wrong. Let me recap:
If I don't put the #synthesize tableView; on the top of the implementation file, the deselection of the row is working fine, but the results are wrong - 8 rows (out of 500) repeating in the tableView.
If I put the #synthesize in the file, the data in the tableView is correct, but there is no animation when i get back to the tableView with the navigation controller.
I also tried to put a UITableView in the nib file of the listviewcontroller, but the results were the same - no deselection of the row. I also tried to deselect row in the viewWillAppear delegate, but the indexPath of the indexPathForSelectedRow is null.
Oh, and I'm using an NSFetchedResultsController. Like I said - the fetched results are correct, but it seems that they're not properly fed to the tableview (if it is not synthesized..)
Thanks!
I might be able to solve your row highlighting issue but you will need to include some code examples so we can help you with the other items...
To deselect a row you can call the method [deselectRowAtIndexPath:animated:] this will allow you to deselect the row before or after you push your detail view controller from your tableView selection delegate. Table View Reference
Thanks for responding!
Hmm..I may have found a solution, but I'm not sure it's correct.. I am implementing the UITableViewController in my new class, but I'm actually using a new UITableView (tableView2) for the data fetching. In the nib file i created the UITableViewController, set the Class name to my custom class BUT I didn't connect the Table View in the Interface Builder with my newly created tableView2. I hope you'll be able to understand.. It's quite complicated, this whole stuff :S
So if I get this right - if I implement an UITableViewController, my class automatically gets a self.tableView? But, like I said in my question, if I don't synthesize the property in the .m file, the controller can't deselect the row automatically..but if I do, the data isn't correct and is repeating..Maybe there is a problem in the cellForRowAtIndexPath, where i get my cells from self.tableView..but It's not logical :S
Anyway, now the row de-selection animation works without my interference and the data displayed is correct. I'm suspecting that the UITableViewController has some other methods that need to be overwritten if using the NSFetchedResultsController.
Do you think my method is incorrect? Having a new UITableView in my custom UITableViewController class?

Information from pushed viewController to rootViewController

Sort of a simple question. I have a tableview in a navigationcontroller. When I touch a cell, it pushes a view controller with the information from the cell, so I can edit it in the new view. Now thats working correct (we can call it the informationpath: "rootviewcontroller -> pushed viewcontroller"). But when I click save in the new view, I want the edited values to travel back to the rootviewcontroller before I call popviewcontroller (informationpath: "pushed viewcontroller -> rootviewcontroller"), so the edited values can be displayed in the tableview.
Whats the correct approach to this?
EDIT:
pushViewController and popViewController is working. I only asked for the best approach to get the edited information back to the rootViewController for display in the tableview, when Save-button (popViewController) was called. I guess I'll just have to edit the pList with the new information directly from the pushed viewController. Though I would prefer sending the new information to the rootViewController and have it handle the access to the pList-file.
I have the same situation - two tableviews. The first TV displays a list of database records and when one is tapped it goes through to the second TableView which displays the details of the record. I do this by pushing the details TableViewController onto the navigation controllers stack. So far so go and quite simple.
The problem I encountered was that after updating the record in the details table view (controller), I wanted to let the list table view controller know, so that it could update the list of records.
The first thing I did was to add a property to the details table view controller so that when a row was selected on the list of records, the list controller could pass the core data managed entity to the details controller.
At the same time, I also added the list controller as a observer of core data change events like this:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dataSaved:) name:NSManagedObjectContextDidSaveNotification object:nil];
So if the details table view and controller update the record, the list controller has it's dataSaved: method called, passing a NSNotification object.
In the dataSaved: method I examine the object and if the core data entity being edited is in the updated list, then I set a flag to signal an update is required. However if there is a record in the inserted list, it means that a new record has been created and inserted into the database, so a flag is set to trigger a full reload of the list table view.
When the user returns to the list view controller, the viewDidAppear: method is triggered. In this method I examine the flags and either call
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
to reload the specific record if the record was updated, or tell the table view to do a full reload if there is an insert of a new record.
Finally I then remove the list controller as an observer of core data notifications because it is no longer interested.
I don't know if this is the recommended way to do this, but so far it's working for me.
You can try to reloadData before popViewController but you should post some code.
All UIViewControllers have a navigationController method. When you push a view controller to a navigation controller, that property is set to point to the navigation controller.
So, just call [self.navigationController popViewControllerAnimated:YES]; in the view controller.
Also, don't confuse views and view controllers. When you click save in the view, you should make sure that the save button calls a method on your view controller, which in turn talks to the navigation controller.
On tapping a row You are going to new view with appropriate information.
Here you perform some operation such as editing data.
So first save the changes on click on save button (By calling an IBAction) and in this IBAction method will check wheter (changes are successfully saved) then call
[self.navigationController popViewControllerAnimated:YES];
And ensure that table reload itself by updated databese (for this change array of data by calling database method in viewWillAppear method).

iphone reload table data

I am trying to update a list in a tableview controller. In viewWillAppear in that particular tableview controller, the tableView is setup with the code:
[self.tableView reloadData];
I am trying to do this refresh from an other Class (DetailViewController), which refers to another view controller.
In a method in DetailViewController I want to reload the data in JobsViewController, but can't do it. I can envision the below code working, but something is still missing. Can anyone please shed some light on this?
[JobsViewController.tableView reloadData];
Did you also change your data source? reloadData does only reload the cells. It doesn't take care of actually updating the underlying datasource. E.g. if you read data from an array in tableView:cellForRowAtIndexPath:, your have to change the array values befor calling reloadData.