iphone - 调用 MyAppDelegate.m 中的方法到 ViewController

标签 iphone ios delegates reloaddata aqgridview

我有 GridViewController。

@interface GridViewController : UIViewController <AQGridViewDelegate, AQGridViewDataSource, LoginViewControllerDelegate, IconDownloaderDelegate, UIScrollViewDelegate> {

NSArray *objects; //main data model
NSMutableDictionary *imageDownloadsInProgress;

}

@property (nonatomic, retain) IBOutlet AQGridView *gridView;

我需要对我的 gridview 调用 reloadData 方法。

当我在 GridViewController.m (viewDidLoad) 中调用 [self.gridView reloadData]; 时,

它重新加载没有问题。

但是我需要在AppDelegate.m中调用这个方法

所以我在 AppDelegate.m 中导入“GridViewController.h”

#import "AppDelegate.h"
#import "GridViewController.h"

并调用方法,

[gridViewController.gridView reloadData];

它不工作。

我怎样才能从我的 delegate.m 调用这个方法到 GridViewController 的 gridView?

最佳答案

尝试在您的 AppDelegate 中发布您的 GridViewController 将捕获的通知。 在 AppDelegate.m 的某个地方,您需要调用您的网格重新加载代码:

[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadGrid" object:nil];

在您的 GridViewController 的 viewDidLoad 中:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadMyGrid)name:@"reloadGrid" object:nil];

在您的 GridViewController 的 viewDidUnload 中:

[[NSNotificationCenter defaultCenter] removeObserver:self];

并且您需要向 GridViewController 添加方法:

- (void)reloadMyGrid {
     [self.gridView reloadData];
}

关于iphone - 调用 MyAppDelegate.m 中的方法到 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10292618/

相关文章:

ios - (iOS Swift) 从 Core Data 获取记录返回 fatal error 或 nil

iphone - 如何将 NSMutableArray 所需的 Item 复制到 NSArray

iphone - self.text 和 _text 之间的真正区别

ios - 有什么方法可以获取 Spotify Premium 帐户进行测试?

ios - 在 Tableview 标题中找到 UIButton 并更改按钮标题

javascript - 为什么不委托(delegate)滚动工作?

ios - 设置委托(delegate)(用于协议(protocol))仅适用于 prepareForSegue?

ios - -[__ NSArrayI objectForKeyedSubscript:]:无法识别的选择器已发送到实例IN Xcode6 Objective-C iOS

ios - 在 120 个字符后附加 readmore 标签,并使其在 ios 中可点击

c# - 当我们在类中或类外定义委托(delegate)时,有什么区别?