0

One view that is a subview of one view controller. And this view will show some data that are stored on one plist file. However, this plist file will be changed on next view controller. When the screen back from next view controller to previous view controller that has the customary view as subview, the data will not be refreshed. In this situation, how can I fix it? And there are several solutions that are provided on the network.

First solution:

if(self isViewLoaded)
{
    self.view = nil;
    [self viewDidLoad];
}

This solution has one problem that the view of controller is black and will not show any others. But if I delete following code, the data on the view could be refreshed.

self.view = nil;

However, there is one problem that I could see some words under this layer. I guess that it will create new layer above the older layer. Because some lighter words that are not the data on current version plist file instead of previous version plist file are on this subview

Second solution:

[self.view setNeedsDisplay];

this code has not any function.

4

1 回答 1

0

您可以使用“下一个视图控制器”中的 NSNotificationCenter postNotifcation。

例如:

-(void)updatePLISTData
{
    // code to download new data for PLIST

    [[NSNotificationCenter defaultCenter] postNotificationNamed:@"notif_plistChanged" .... object:thePlistObject ];
}

确保你记得向你的“父视图控制器”添加一个观察者,它会推动你的“下一个视图控制器”。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updatePlist:) object:nil];

并且还删除了观察者

-(void)dealloc
{
   [[NSNotificationCenter defaultCenter] removeObserver:self];
   ...
   [super dealloc];
}

收到通知后,通知将调用您在添加观察者时指定的任何方法。在这种情况下,您有

-(void)updatePlist:(NSNofitication *)paramPlist
{
    self.plist = paramPlist;
}
于 2012-08-21T08:44:49.210 回答