0

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.

4

2 回答 2

1

由于您没有提供代码,所以我无法确定您应该在哪里重新加载您的表格视图。

你必须打电话

[self.tableView reloadData];

就在您完成使用 NSFileManager 将数据保存在 plist 中之后。

于 2013-04-30T21:10:15.967 回答
0

表格视图没有更新,因为您可能没有在调用表格视图[self.tableview reloadData];时调用reloadData它应该更新表格视图。

由于您在将每个视图推送到堆栈时使用标签栏控制器,因此它会停留在那里,您需要检测视图是否再次出现并调用reloadData方法。

添加completed.m这个:

-(void) viewWillAppear:(BOOL)animated{
   [self.tableview reloadData];
}

incomplete.m检测是否NSFileManager保存数据然后调用[self.tableview reloadData];

还有其他方法可以解决这个问题,您可以通过DelegateNSNotifications模式在视图控制器之间进行通信。因此,假设您保存了调用delegateNSNotification方法的数据,并且接收器视图控制器运行您想要的方法。在您的情况下刷新表格视图

如何设置一个简单的委托来在两个视图控制器之间进行通信?

http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_nsnotificationcenter/

于 2013-04-30T21:17:33.960 回答