Reload TableView Tab Bar Application - uitableview

I have a tab bar application that displays tableviews in two of the tabs. The tableviews are populated using NSFileManager to read the contents of a plist file stored with user data. One of the tabs displays the "complete" items, the other tab displays the "Incomplete" items. As the user selects a row, a page with the details of the item selected is displayed. In the incomplete table there is a button the user can press to move these details from the "Incomplete" table to a "Completed" table. The plist is then updated using NSFileManager to change a field detailing if the item is in the complete or the incomplete list for this item.
The problem I have is that the changes are not updated on the two tables just by selecting between the two tabs. The user has to quit the application and start it up again to see the item moved from one table to the other.
The data seems to be updated its just the view that doesn't update.
I'm new to cocoa so any help at all would be greatly appreciated.

As you haven't provided the code, so i cannot tell where exactly you should reload your tableview.
You have to call
[self.tableView reloadData];
just after you are finished using NSFileManager to save your data in the plist.

Table views are not updating because you are probably not calling [self.tableview reloadData]; when you call reloadData for a tableview it should update the tableviews.
Since you are using tab bar controllers when each view is pushed to the stack it stays there you need to detect if view is appear again and call reloadData method.
in completed.m add this:
-(void) viewWillAppear:(BOOL)animated{
[self.tableview reloadData];
}
in incomplete.m detect if NSFileManager is saved data then call [self.tableview reloadData];
there are also other ways to solve this problem, you can communicate between viewcontrollers via Delegate or NSNotifications pattern. So lets say you saved the data you call your delegate or NSNotification method and receiver view controller runs your desired method. In your case refreshes the tableview
How do I set up a simple delegate to communicate between two view controllers?
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_nsnotificationcenter/

Related

I need to delay the call of UITableView until other methods have finished executing

I am building an ios app, that uses google places api to locate certain places and then display the details in a table view. But the problem, that I am facing is that
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
method gets called before the data acquired from the api is stored in the memory. So it (obviously) returns 0, and details are not displayed. Is there some way I can delay the call of Table View?
Well your only option is to not show the table view until there is data there.
Assuming this is not viable, why not just show an activity popup indicating that you are loading information and then when its loaded, drop the activity indicator and call [self.tableview reloadData];
You can reload your Table by below line,
[tableView reloadData];
You can make the tableview invisible and make it visible right before reloading the table.

how to create refresh button in UITableView

I want to create one application that read many data from json and show them in tableview.
I want to create one button that when to click on it this page for a second time to be refresh and take data from json (check json again and if this json changed tableview also changed)
I dont know how create this function that refresh this page and run code at first.
please tell me about it.
[self.tableView reloadData]
to load more data from webserver in to table
Put a button in header of section. I think that is the best place. In target method of that button call json and download all data. then call [self.tableView reloadData]. It will call all table methods like number of row , sections, cellForRow.
Why don't you use the Default RefreshControl provided in iPhoneSDK.
A UIRefreshControl object provides a standard control that can be used to initiate the refreshing of a table view’s contents. You link a refresh control to a table through an associated table view controller object. The table view controller handles the work of adding the control to the table’s visual appearance and managing the display of that control in response to appropriate user gestures.
Check this to learn about its implementation : Working with UIRefreshControl
You can place a UIToolBar above the tableview. In that you can have a barbutton, to which you could give an action to fetch the data again. Once the data fetch is done, call
[self.tableview reloadData];

Reload UITableView in edit mode

I have a dictionary that holds every item in a list. I then have a plist that holds user information for each item in the list, including if the item has been collected or not. Then I load a UITableView with information based on the plist against the dictionary, only displaying items that the user still has not collected.
Users can tap on each row and navigate to a UIView page with information for the item with a static button to add the item to the completed list. When the button is pressed the program changes the "Completed" field related to the item in the users plist file to "YES" and when the user navigates back to the UITableView the item is removed from the list by calling [self.tableView reloadData] in the viewDidAppear function.
I also want the user to be able to enter "Edit mode" in the UITableView and select multiple rows to be added in one go. I have managed to get the functions working correctly, using self.tableView.allowsMultipleSelectionDuringEditing = YES; and NSArray *temp = self.tableView.indexPathsForSelectedRows; but the tableView will not refresh the screen until the user navigates out of the page and back in again. I have tried adding the [self.tableView reloadData] in different functions but none of them work.
Thanks in advance for any help.
I cannot think of a reason why reloadData should not work, but IMO you should try
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation: (UITableViewRowAnimation)animation
instead of reloadData(if you haven't already).
Also http://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/ManageInsertDeleteRow/ManageInsertDeleteRow.html#//apple_ref/doc/uid/TP40007451-CH10-SW9 this could be of help.
Let me know if this works for you.

numberOfSectionsInTableView is requested in/after viewDidLoad ONLY if tableview is empty

A simple tableviewController, empty. A modal that can be launched from a button. No data in the data source for the tableview, and no rows displayed.
I open the modal, use it to add an item, and return to the tableview controller. The tableview updates itself automatically, and the new row is displayed.
I add a second item. The table view does NOT update automatically.
I can tell by logging inside numberOfSectionsInTableView that even if I go to add the first item and cancel, the tableview refreshes - it asks for the number of sections, rows, and the cell to display (if there is one). But not if there is one pre-existing row in the table.
I've scoured my code but can't find anything that would cause the tableview to know when the first item is added, but none afterwards.
Any ideas?
EDIT - I have further narrowed my issue so will close this shortly and have posted a more specific question at Why does an empty tableView check the number of sections but a non-empty one does not?
from Apple's documentation:
UITableView overrides the layoutSubviews method of UIView so that it
calls reloadData only when you create a new instance of UITableView or
when you assign a new data source.
maybe you are setting data source of table view after showing that modal? So at the second time data source does not changes and tableView does not update.
another key (I'm not sure about that) may be the showing of the modal first time. The method -addSubview for modal is causing -layoutSubviews.

Updating a UITableView's data

In my application, I have a UITableView with a few rows (let's call it TV1), now, at the bottom of these rows is a row that drills down into another (TV2). This new TV2 asks you which type of data you would like to add to the first view. Then, when the user selects which kind, they're brought to another view, in which they fill in some fields, the data is saved, and they're sent back to TV1, however, the data they entered, isn't loaded and I'm not really sure how to do this. Any ideas?
Maybe you did this already, but how about using [TV1 reloadData];? This forces the entire table to reload, yet there are also more specific methods for reloading just the cells that have been altered. See also the documentation: UITableView
Reload your table view by calling [self.tableView reloadData] in the viewcontroller's viewWillAppear: method. It will be called when the user switches back to your view. Right before it is actually put on screen.

Resources