从iOS中的App Delegate调用当前视图控制器中的方法 [英] Calling method in current view controller from App Delegate in iOS
问题描述
我有两个视图控制器(BuildingsViewController和RoomsViewController),它们都使用名为upload的App Delegate中的一个函数。 upload函数基本上执行HTTP请求,如果成功或不成功,则触发uialertview。这很好。
I have two view controllers (BuildingsViewController and RoomsViewController) that both use a function within the App Delegate called upload. The upload function basically does an HTTP request, and if its successful or unsuccessful, triggers a uialertview. This is working fine.
我正在努力的部分来自app delegate的 connectionDidFinishLoading
方法。我需要能够通过该视图控制器的 viewWillAppear
方法基本刷新当前视图控制器。在每个视图控制器的 viewWillAppear
函数内,我有代码,用于确定底部工具栏上的按钮。
The part I'm struggling with is from within the app delegate's connectionDidFinishLoading
method. I need to be able to basically refresh the current view controller via perhaps viewWillAppear
method of that view controller. Inside the viewWillAppear
function of each view controller I have code which determines the buttons on the bottom toolbar.
我希望每个视图控制器的工具栏中的上传按钮在通过应用代表完成上传时自动删除。
I want the "upload" button in the toolbar of each view controller to automatically be removed when the uploading is done via the app delegate.
我已尝试在 connectionDidFinishLoading
方法中执行 [viewController viewWillAppear:YES]
应用程序委托,但它永远不会被调用。
I've tried doing [viewController viewWillAppear:YES]
from within the connectionDidFinishLoading
method of the app delegate, but it never gets called.
我希望我足够清楚。非常感谢任何帮助。
I hope I'm clear enough. Any help is greatly appreciated.
谢谢。
推荐答案
要做如果视图已经显示,则视图的刷新不会调用 viewWillAppear
。您要做的是以下内容:
To do the refresh of the view do not call viewWillAppear
if the view is already displayed. What you want to do is the following:
当 ConnectionDidFinishLoading
方法在通知后触发
[[NSNotificationCenter defaultCenter] postNotificationName:@"refreshView" object:nil];
在 viewController
中观察此通知。你可以通过将此代码添加到init或 viewDidLoad
方法
In your viewController
observe for this notification. You do it by adding this code to your init or viewDidLoad
method
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshView:) name:@"refreshView" object:nil];
现在实现 - (void)refreshView:(NSNotification *)通知您的
viewController
中的code>方法可根据自己的喜好管理视图。
Now implement -(void)refreshView:(NSNotification *) notification
method in your viewController
to manage your view to your liking.
这篇关于从iOS中的App Delegate调用当前视图控制器中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!