Why my tableView doesn't update without scrolling it down? - iphone

I am making an nav based app. in my table view i am parsing a xml and showing its data. when i enter new feed item in my xml and click refresh button, my data updates but it didn't appear in tableView untill i scroll it down. When i scroll it down it appears. Can anybody tell me why its happening like that? I want new data appear when i enter the feed item without scrolling my tableView down. Thanx for help

you need to call [self.tableView reloadData] to update the tableView with new contents

Did you call [tableView reloadData] when the data has been refreshed?

You need to reload the cells (or the entire table) for the new data to appear.
Depending on if you return parsed results right away or all results after the entire xml-file has been parsed.
The code to update the table is:
[myTableView reloadData];

You have to call [tableView reloadData] to refresh the data from the UITableView.

Call [tableView reloadData] when the parsing is completed

I'm not exactly sure what you mean. A simple reload is:
[myTableView reloadData]
in the UITableViwController
[self.tableView reloadData]
If you scroll down, new cells that are rendered will use the new data. but cells that are on display have to be told to update immediatly.

Not just -reloadData, you can use any of these:
reloadData
reloadRowsAtIndexPaths:withRowAnimation:
reloadSections:withRowAnimation:
reloadSectionIndexTitles
Basically, you'll need to tell your tableview that your data has changed so it knows to change that. You can do it with fancy animations and whatnot so that the user isn't confused when what's displayed on screen suddenly changes.

Related

Update UITableView While Looking at View?

I am currently building a UITableView that reads an array and displays it on a TableView. I am continually adding to the array I would like to have a button on the view that once is clicked it updates the UITableView.
How do I implement a reload of the UITableView from the new array I just built?
If you are adding and removing items one to a few at a time you will likely want to implement the animated table view methods for insertion and deletion.
When you add or remove an item from the table view you will prepare by calling [tableView beginUpdates] make your array modifications and then call [tableView endUpdates]
Between the begin and end update calls you will perform the actually deletion/insertion.
For deletion you should use
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
Notice UITableViewRowAnimationBottom you will want to play around with this to get the best animation depending on the position of the element. Also iOS5 has a enum value something like UITableViewRowAnimationAutomatic and it will use the best option.
For insertion you should use
insertRowsAtIndexPaths:withRowAnimation: the same way I show above with delete.
For more info check out the section with these methods listed in the UITableView class reference
The function you're looking for is [self.tableView reloadData];. Here's a link to the Apple documentation for UITableView.

iPhone - changing contents of a UITableViewCell inside a navigationController

I have a UITableView with some cells in it that have people's names. When the user clicks on a cell, the Navigation Controller pushes a new view onto the stack that shows detailed info for that person. When the user is done and clicks the button to return to the previous view, the tableview is again shown. The problem is that I want to edit the cell text (or just mark the cell in some way) to show that the user has clicked on that cell. In my cellForRowAtIndexPath: method I have set up code that should change the text of the cell after a user clicks on that cell. I set up break points and it IS entering cellForRowAtIndexPath: when the detail view is popped and the tableview is again shown. It's entering the segment of code in cellForRowAtIndexPath: that should change the text, but when it comes up on screen, the text has not been changed. Does anyone have any ideas as to what is going on? Thanks.
EDIT: I figured it out. I just needed to call [tableView reloadData]; instead of calling the cellForRowAtIndexPath method. Not sure why that works differently, but it fixed it.
I guess I'll help you out. You don't need to credit me with the answer though.
cellForRowAtIndexPath:
that method is called within the framework when a cell is being refreshed from the queue or when it needs to be created. You should not call this method.
[tableView reloadData];
that method is basically a refresh on all of the visible cells show in the UITableView. This is the method you should call if you change information in your data source or you need to (force) update the appearance of your cells.
It's Good You Have Reload Table And Changed The Text But If YouJustIndicate NAd Don't Want To Change The Text The nYou Can Use elow Given Text ....
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
It Will Check Mark Particuler Cell Which You Click/Visited......
Hope You Like This Solution.....

Update UITableViewCell without reload

So here's my situation:
I have a UITableView where each cell has some buttons.
In the cellForRowAtIndexPath I set the indexpath of the row so when the a button is clicked I know what row was clicked.
One of the buttons is a delete button and when pressed I remove the backing data and delete the row from the table.
The problem I'm having is that after I delete a row the indexPath's of the other rows are incorrect as the other rows have not been redrawn. The only way I can find to redraw the table is to call reload but this messes up the animation.
I figure this kind of problem must have been addressed before. Does anyone have any suggestions on how to get around this? I'm ok with changing the way I've designed my buttons to work if there is a better way.
Think you need to use this...
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
Apple reference!
You should be able to redraw the tableview without a full reload by starting and ending an update like this:
[tableView beginUpdates];
[tableView endUpdates];
call the method:
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
It is better not to store the indexPath with the buttons. In the button action handler (which is either a method in your cell subclass or in your viewController) you could identify the cell, and subsequently determine the indexPath using -indexPathForCell:.

Reload tableview iphone developer

I have a feed reader that read automatically the homepage of my website! But when I change the feed URL and reload data the cell isn't reloaaded! Infact I must scroll the cell view (infact with this action is called the didselectrowatindex method) to reload data in the cell with the new ones.
I tried [tableview reload]; without any results....
Is there a method to reload all content in the cell without scrolling it?
Thanks
Well, it should be [tableview reloadData]
If it's not working, then maybe you have a problem with your IBOutlet?

Redoing UITableView layout when user taps Edit button?

I have a UITableView with complex content. The user can edit (rearrange and delete) the cells when tapping the Edit button the standard way. But I want the cells to look different in "edit" mode.
Question:
How to change the UITableView Layout in edit mode, including changing row height?
So far, this is what I have:
The Edit button sends a WillTransitionToState/DidTransitionToState message to each uitableviewcell (UITVC). I have subclassed UITVC and react to these inside each cell, hiding and removing and reshuffling as needed. But, changing the row height is beyond the scope of one cell.
There does not seem to be a message sent to UITableView when user taps edit. There is a - tableView:commitEditingStyle:forRowAtIndexPath: sent to data source after editing a particular row.
Inside heightForRowAtIndexPath, I can query the current mode using the tableView.editing property, and report height as appropriate. And I can trigger re-flowing the table, including recomputing the heights, by invoking [tableView reloadData]. But, when do I call it?
I could send messages from the cells from within WillTransitionToState back to the "owning" table view, and call reloadData when I get them. But this sounds fragile and there must be a better way.
Rhythmic is right. Using reloadData kills the nice editing animation.
This problem is addressed in this post:
Can you animate a height change on a UITableViewCell when selected?
Instead of using reloadData, do the following after calling setEditing:animated.
[tableview setEditing:editing animated:YES];
[tableview beginUpdates];
[tableview endUpdates];
If you wish for your table cells to change their format in response to whether or not the table is in editing mode, you could override -setEditing:animated: in your UITableViewController and trigger a reload (via -reloadData) of the table view on a change of editing state.
Within your UITableViewController's -tableView:cellForRowAtIndexPath: method, you could check for whether or not the table was in the editing state by querying the editing property on the table view, and then return a different cell type depending on which state the table is in.