我有 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/