iphone reload table data - iphone

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.

Related

how do I reload the data in UiSearchDisplayController and Tableview after modific data?

where search data and click item, a new view appears, where I can change the data. If change data and return to uisearchdisplaycontroller, data not reload (also in tableView). How do i reload data?
sorry for my english :)
The UITableView Class has a method called reloadData which can be called and it reloads all of your tableView's rows. UITableView Class Documentation
If you only need to reload specific rows you can use reloadRowsAtIndexPaths:withRowAnimation: passing in an array of NSIndexPath and a row animation.
You can also reload entire sections using reloadSections:withRowAnimation:.

TableView is not showing data?

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

How do I maintain the UITableView selected row when returning from a UINavigationController child screen?

I have a UITableView of customers where a row/customer is selected. The user can then push another view on the UINavigationController stack to add a new customer. When I pop the child screen and return to the UITableView the previously selected row is no longer selected.
I can re-select the row in viewDidAppear() but it looks bad as you can see the deselect and the select. Is there a way to maintain the selected row when returning from the child screen?
I assume you are using a table view controller, as otherwise it is your responsibility to write this behaviour anyway. In a table view controller, though, it's easy. Just add in viewDidLoad:
self.clearsSelectionOnViewWillAppear = NO;
That will keep the row selected, unless you manually deselect the row or the user selects another row on the table.
If you select it in viewWillAppear:, it should get selected without the user seeing it. Would that solve your problem?
You need to call:
[tableView deselectRowAtIndexPath:indexPath animated:YES];
This is found in the didSelectRowAtIndexPath delegate method for a UITableView.
By default, a selected row gets deselected (with animation) when you return to that VC.
So, if you push a DetailViewController, the cell stays selected until you return to the RootViewController and then gets deselected automatically.
I used to have such a problem too. Make sure to always call the superclass's implementation of methods such as viewWillAppear, viewWillDisappear etc.
Also, do not call deselectRowAtIndexPath: manually.
This is possible :
Only in once case: If you have the static content in TAbleView,
just reload the TableView in ViewDidLoad only, not in View will Appear.
whereas make sure, you don't allow table to reload anywhere in same class in any method. Then you can achieve what you want.
The cell get deselect because of reload the TAbleView.
But for Dynamic content, you need to use the delegate method:
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
In this you need to pass the indexPath which you want to show selected with the scrollPostion same as tableviewposition.
You cannot have a tableViewCell selected all the time. It gets back to normal once it serves its purpose. I think you meant highlighted or appear to be selected, and I am answering the question based on that.
Get the row that was selected at the cellForRowAtIndexPath. When you pop your navigation controller and come back to the tableView, go the the cellForRowAtIndexPath and have that cell highlighted (You can use any UIColor as you wish) - there is no specific way to highlight stuff - use your imagination - Default highlight style is Blue, while the text is White.
How is this done ?
Find selected row in cellForRowAtIndexPath
Store is in an external variable / or NSUserDefaults and you can also use NSUserDefaultsto communicate between screen to find out if item was popped from that screen.
[tableView reloadData] in viewWillAppear
Check for NSUserDefaults value in cellForRowAtIndexPath and modify that cell with cell.backgroundColor or something.
Without some code, I can just give an advice : stop using [tableView reloadData], use [tableView beginUpdates], [tableView endUpdates] and – insertRowsAtIndexPaths:withRowAnimation: and – reloadRowsAtIndexPaths:withRowAnimation:. Things should work as expected.

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.

iOS tableview data change

i've a method that populate a UITableView without problem.
if i go to setting page, change some settings and come back to my rootview i call the method with new settings but my UITableView display always the last values.
Any help?
[self.tableview reloadData];