0
我的數據存儲方法位於AppDelegate中。每當數據被保存到數據庫中時,我想檢查SecondView是否可見。
如果是,則從數據庫重新加載屏幕上的值。 如果不是,我將在屏幕上顯示包含最新值的視圖。通過數據庫更新移至故事板中的視圖
我想是這樣的:
delegate.m
// I want to update view
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SecondViewController *SecondVC = (SecondViewController *)[storyboard instantiateViewControllerWithIdentifier:@"SecondVC"];
if (SecondVC.isVisible)
{
NSLog(@"SecondVC is visible");
[SecondVC updateDisplayValue];
}
else
{
self.window.rootViewController = SecondVC;
NSLog(@"SecondVC not visible");
}
SecondViewController.m
- (BOOL)isVisible {
return [self isViewLoaded] && self.view.window;
}
- (void)updateDisplayValue
{
[self LatestMeasurementFromSQLite];
[self.date setText:self.measurementTime];
}
它不工作,因爲它應該的ISVISIBLE有去無回是可見的,並且updateDisplayValue不會更新已經顯示的視圖。
我相信問題是,我已經重新開始了一個名爲SecondVC新的觀點,這是不是在屏幕上顯示的一個。但是,AppDelegate如何獲得當前顯示視圖?
請幫忙!非常感謝!