robbiecutting
robbiecutting

Reputation: 241

Reload TableView Tab Bar Application

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.

Upvotes: 0

Views: 1048

Answers (2)

SpaceDust__
SpaceDust__

Reputation: 4914

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/

Upvotes: 0

Jessica
Jessica

Reputation: 1498

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.

Upvotes: 1

Related Questions